home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / skt2cdf2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-04  |  75.5 KB  |  3,195 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        CDFskeleton.  Part 2 of 2.
  4. *
  5. *  Version 1.0, 4-Mar-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0   4-Mar-92, S Sudarsan       Original version.  This is a crunching
  10. *             J Love       together of all the separate files which
  11. *                   used to make up CDFskeleton.  Two source
  12. *                   files necessary for IBM PC compilation.
  13. *   
  14. ******************************************************************************/
  15.  
  16. #include "cdfdist.h"
  17. #include "skt2cdf.h"
  18.  
  19. /*****************************************************************************/
  20.  
  21. void AnalyseNRVData(num_values, numdims, var_name, str_len)
  22. /* called after encountering   a . */
  23. long num_values;/* the number of NRV values to be read */
  24. long numdims;
  25. char *var_name;
  26. long str_len;
  27. {/* assumed that when this is called the cdf_data_type is that of the var */
  28.  
  29.   long count = 0, len, flag, offset, diff;
  30.   char *buff, *dummy_ptr, *temp_addr,
  31.        *temp_ptr;
  32.   long  num_index, var_data_type,  *index_ptr, prev_offset;
  33.   
  34.   while(count < num_values)
  35.   {
  36.     flag = 0;
  37.  
  38.     while(flag != 1)
  39.      {
  40.        prev_offset = ftell(file_ptr);/* the position before the NRV 
  41.                                       values or new variable name */
  42.      
  43.       if(fgets(obuffer, 134, file_ptr) == NULL)
  44.         {
  45.       if (mLog) {
  46.             fprintf(stderr, "\nINCORRECT NRV DATA SPECIFICATION\n");
  47.             fprintf(stderr,"%s\n",obuffer); 
  48.       }
  49.           DeleteCDF(id);
  50.           ExitBAD;
  51.         } 
  52.      
  53.        len = strlen(obuffer);
  54.  
  55.        *(obuffer + (len -1)) = '\0';
  56.  
  57.        buff = TrimBlanks(obuffer);
  58.  
  59.        switch(*buff)
  60.        {
  61.          case '!':
  62.          break;
  63.          case '\0':
  64.          break;
  65.          default:
  66.           flag++;
  67.          break;
  68.        }/* end switch */
  69.      }/* end while */
  70.  
  71.      
  72.  
  73.      if(*buff != '[')/*no data in  the skeleton table */
  74.       {
  75.         
  76.         if(fseek(file_ptr, prev_offset, 0) != 0)/* move back */
  77.         {
  78.           if (mLog) fprintf(stderr, "Could not reposition file pointer\n");
  79.           DeleteCDF(id);
  80.           ExitBAD;
  81.         }
  82.      
  83.         ReadNRVFile(num_values, numdims, var_name, str_len);
  84.    
  85.         return;/* get back to variable line and return */
  86.       }
  87.  
  88.      buff++;/* move past the [ */
  89.  
  90.  
  91.    
  92.      buff = TrimBlanks(buff);
  93.  
  94.  
  95.      if((*buff == '\0')||(*buff == '!'))     
  96.        buff = ProcessWrapLines(file_ptr, obuffer,
  97.               "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  98.  
  99.  
  100.      ParseNumericValue(file_ptr, buff, ']', 
  101.      "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");/* loaded in str_ptr */
  102.      /*num_index = ProcessNumericString();*//* dimension of the matrix*/
  103.  
  104.      
  105.      if(!numdims && !strlen(str_ptr))
  106.       {
  107.          free(str_ptr);
  108.          str_ptr = (char *) malloc(2);/* one for a value one for \0 */
  109.          strcpy(str_ptr, "0");
  110.          num_index = ProcessNumericString();
  111.          num_index--;/* was 1 now 0 */
  112.       }
  113.      else
  114.       {
  115.          num_index = ProcessNumericString();
  116.  
  117.          if(num_index != numdims)
  118.          {
  119.            if (mLog) fprintf(stderr,
  120.                 "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  121.            DeleteCDF(id);
  122.            ExitBAD;
  123.          }
  124.       }
  125.  
  126.  
  127.        var_data_type = cdf_data_type;/* copy the current type*/ 
  128.        cdf_data_type = CDF_INT4;/* for the array indexes */
  129.  
  130.       TypeConvertString(num_index);  /* int4_ptr has it *//*V 1.4*/
  131.  
  132.        cdf_data_type = var_data_type;
  133.  
  134.       index_ptr = (long *) malloc(num_index * sizeof(long));    /* V1.2 */
  135.  
  136.       len = 0;/* index ptr is an array containing the subscripts*/
  137.  
  138.       while( len <= num_index -1 )
  139.        {
  140.          *(index_ptr + len ) = *(int4_ptr + len) - 1;
  141.          len++;/* - 1 because internally the matrix starts at 0 */
  142.        }
  143.  
  144.  
  145.      /* free the allocated spaces for the NRV variable values */
  146.   
  147.       len = 0;
  148.   
  149.      while(len <= num_index - 1)
  150.        {
  151.         free(int4_ptr + len); 
  152.         len++;
  153.        }
  154.  
  155.       len = 0;
  156.       while(*(c_ptr + len) != NULL )
  157.        {
  158.         dummy_ptr = (char *) *(c_ptr + len);
  159.         free(dummy_ptr);
  160.         len++;
  161.        }
  162.  
  163.      cfree(c_ptr);
  164.      c_ptr = NULL;
  165.      free(str_ptr);
  166.      str_ptr = NULL;
  167.      buff = strchr(buff, '=');/* look for the = */
  168.  
  169.      if (buff == 0)
  170.      {
  171.        buff = ProcessWrapLines(file_ptr, obuffer, 
  172.        "\nINCORRECT NRV DATA SPECIFICATION\n");
  173.  
  174.        if(*buff != '=')
  175.        {
  176.     if (mLog) {
  177.           fprintf(stderr, "\nINCORRECT NRV DATA SPECIFICATION\n");
  178.           fprintf(stderr,"%s\n",obuffer); 
  179.     }
  180.         DeleteCDF(id);
  181.         ExitBAD;
  182.        }
  183.      }
  184.  
  185.      buff++;/* get past the  = */
  186.  
  187.      buff = TrimBlanks(buff);
  188.  
  189.      switch(*buff)
  190.      {
  191.        case '!':
  192.        {
  193.          buff = ProcessWrapLines(file_ptr, obuffer, 
  194.          "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  195.        }
  196.        break;
  197.        case '\0':
  198.        {
  199.          buff = ProcessWrapLines(file_ptr, obuffer, 
  200.          "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  201.        }
  202.        break;
  203.        default:
  204.        break;
  205.      }/* end switch */
  206. /*****************************/
  207.      if((cdf_data_type == CDF_CHAR)||(cdf_data_type == CDF_UCHAR))
  208.        {
  209.          if(*buff != '{')
  210.            {
  211.          if (mLog) {
  212.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  213.                fprintf(stderr,"%s\n",obuffer); 
  214.          }
  215.              DeleteCDF(id); 
  216.              ExitBAD;
  217.            }
  218.  
  219.           buff++;
  220.  
  221.           buff = TrimBlanks(buff);
  222.  
  223.  
  224.           if((*buff == '\0')||(*buff == '!'))
  225.             buff = ProcessWrapLines(file_ptr, obuffer,
  226.             "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  227.  
  228.           str_ptr = NULL;
  229.            ParseValue(file_ptr, buff, *buff, 
  230.            "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  231.  
  232.           c_ptr = (char **) calloc(2, sizeof(char *));
  233.  
  234.           len = strlen(str_ptr);
  235.           /*printf("%s\n", str_ptr);*/
  236.           *(c_ptr) = (char *) malloc(len + 6); 
  237.  
  238.           strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  239.  
  240.           dummy_ptr = (char *) *c_ptr;
  241.  
  242.           *(dummy_ptr + len) = '\0';
  243.  
  244.           *(c_ptr + 1) = NULL;
  245.  
  246.        }
  247.      else if((cdf_data_type == CDF_EPOCH)&&(strchr(buff, ':')))
  248.         {
  249.     temp_addr = buff;/* start of the variable */
  250.  
  251.        len = StringTraverse(buff);
  252.  
  253.        buff = buff + len;/* get past the variable value */
  254.  
  255.           buff = TrimBlanks(buff);       
  256.  
  257.           switch (*buff)
  258.           {
  259.             case '!':
  260.             {
  261.          if (mLog) {
  262.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  263.                fprintf(stderr,"%s\n",obuffer); 
  264.          }
  265.              DeleteCDF(id); 
  266.              ExitBAD;
  267.             }
  268.             break;
  269.             case '\0':
  270.             {
  271.          if (mLog) {
  272.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  273.                fprintf(stderr,"%s\n",obuffer); 
  274.          }
  275.              DeleteCDF(id); 
  276.              ExitBAD;
  277.             }
  278.             break;
  279.             default:
  280.             break;
  281.           }/* end switch */
  282.  
  283.  
  284.           len = StringTraverse(buff);/* the second string */
  285.           buff = buff + len;
  286.            
  287.           buff = TrimBlanks(buff);
  288.  
  289.           switch(*buff)
  290.           {
  291.             case '!':
  292.             break;
  293.             case '\0':
  294.             break;
  295.             default:
  296.             {
  297.          if (mLog) {
  298.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  299.                fprintf(stderr,"%s\n",obuffer); 
  300.          }
  301.              DeleteCDF(id);
  302.              ExitBAD;
  303.             }
  304.             break;
  305.           }/* end switch */
  306.           buff--;/* get before it */
  307.  
  308.       len = buff - temp_addr + 1;/* lenghth of string to be copied */
  309.  
  310.       str_ptr = (char *) malloc(len + 1 + 6);/* copy it into str_ptr */
  311.  
  312.       strncpy(str_ptr, temp_addr, len);
  313.       
  314.       *(str_ptr + len) = '\0';
  315.  
  316.       c_ptr = (char **) calloc(2, sizeof( char *));/* 2 pointers */
  317.  
  318.       *(c_ptr) = (char *) malloc(len + 6);
  319.  
  320.       strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  321.  
  322.       dummy_ptr = (char *) *c_ptr;
  323.  
  324.       *(dummy_ptr + len) = '\0';
  325.  
  326.       *(c_ptr + 1) = NULL;
  327.         }
  328.        else
  329.         {
  330.     temp_addr = buff;/* start of the variable */
  331.  
  332.        len = StringTraverse(buff);
  333.  
  334.        buff = buff + len;/* get past the variable value */
  335.  
  336.           buff = TrimBlanks(buff);
  337.  
  338.           switch(*buff)
  339.           {
  340.             case '!':
  341.             break;
  342.             case '\0':
  343.             break;
  344.             default:
  345.             {
  346.           if (mLog) {
  347.                 fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  348.                 fprintf(stderr,"%s\n",obuffer); 
  349.           }
  350.               DeleteCDF(id);
  351.               ExitBAD;
  352.             }
  353.             break;
  354.           }/* end switch */
  355.           buff--;/* get to the previous char */
  356.  
  357.       len = buff - temp_addr + 1;/* lenghth of string to be copied */
  358.  
  359.       str_ptr = (char *) malloc(len + 1 + 6);/* copy it into str_ptr */
  360.  
  361.       strncpy(str_ptr, temp_addr, len);
  362.       
  363.       *(str_ptr + len) = '\0';
  364.  
  365.       c_ptr = (char **) calloc(2, sizeof( char *));/* 2 pointers */
  366.  
  367.       *(c_ptr) = (char *) malloc(len + 6);
  368.  
  369.       strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  370.  
  371.       dummy_ptr = (char *) *c_ptr;
  372.  
  373.       *(dummy_ptr + len) = '\0';
  374.  
  375.       *(c_ptr + 1) = NULL;
  376.  
  377.         }/* end else */
  378. /****************************/
  379.  
  380.      if((cdf_data_type == CDF_CHAR)||(cdf_data_type == CDF_UCHAR))
  381.       {
  382.         /* V1.3 */
  383.        /* assumption - no ! terminates the nrv data - only '\0' */
  384.        /* padd the nrv value with blanks */
  385.         if(strlen(str_ptr) <= str_len)
  386.          {
  387.           if(strlen(str_ptr) < str_len)  
  388.           {
  389.             diff = str_len - strlen(str_ptr);
  390.             temp_ptr =  (char *)malloc(str_len + 1);
  391.             strcpy(temp_ptr, str_ptr); 
  392.  
  393.             offset = strlen(str_ptr); 
  394.  
  395.             while(diff != 0)
  396.             {
  397.               *(temp_ptr + offset) = ' ';
  398.               diff--;
  399.               offset++;
  400.             }
  401.  
  402.             *(temp_ptr + (str_len + 1)) = '\0';
  403.  
  404.             free(str_ptr);
  405.            
  406.             str_ptr = (char *)malloc(str_len + 1 +6);
  407.             strcpy(str_ptr, temp_ptr);
  408.             *(str_ptr + (str_len + 1)) = '\0';
  409.             free(temp_ptr);
  410.            }
  411.           status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  412.                               str_ptr );
  413.          }
  414.         else
  415.           {
  416.        if (mLog) {           
  417.              fprintf(stderr, "\nSTRING SIZE AND NRV VALUE DON'T MATCH\n");
  418.              fprintf(stderr, "NRV VALUE TRUNCATED\n");
  419.        }           
  420.            status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  421.                               str_ptr );
  422.           }
  423.       }
  424.      else
  425.      {
  426.        if(!strncmp(var_name,"EPOCH",5))/* V 1.4 */
  427.           TypeConvertString(1);  /* only one value - epoch*/
  428.         else
  429.           TypeConvertString(1);  /* only one value non epoch */
  430.  
  431.         /*len = 0;
  432.         while(len <= num_index - 1)
  433.         {
  434.          printf("index %ld\n", *(index_ptr + len));
  435.          len++;
  436.         }*/
  437.  
  438.         switch(cdf_data_type)
  439.         {
  440.           case CDF_INT1:
  441.           {
  442.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  443.                           int1_ptr);
  444.           
  445.             free(int1_ptr);
  446.           }
  447.           break;
  448.           case CDF_INT2:
  449.           {
  450.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  451.                           int2_ptr);
  452.             free(int2_ptr);
  453.           }
  454.           break;
  455.           case CDF_INT4:
  456.           {
  457.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  458.                           int4_ptr);
  459.           
  460.             free(int4_ptr);
  461.           }
  462.           break;
  463.           case CDF_UINT1:
  464.           {
  465.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  466.                           uint1_ptr);
  467.           
  468.             free(uint1_ptr);
  469.           }
  470.           break;
  471.           case CDF_UINT2:
  472.           {
  473.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  474.                           uint2_ptr);
  475.           
  476.             free(uint2_ptr);
  477.           }
  478.           break;
  479.           case CDF_UINT4:
  480.           {
  481.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  482.                           uint4_ptr);
  483.           
  484.             free(uint4_ptr);
  485.           }
  486.           break;
  487.           case CDF_REAL4:
  488.           {
  489.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  490.                           real4_ptr);
  491.           
  492.             free(real4_ptr);
  493.           }
  494.           break;
  495.           case CDF_REAL8:
  496.           {
  497.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  498.                           real8_ptr);
  499.            /*printf("%e\n", *real8_ptr);*/
  500.             free(real8_ptr);
  501.           }
  502.           break;
  503.           case CDF_EPOCH:                    /* V1.1... */
  504.           {
  505.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  506.                           real8_ptr);
  507.             free(real8_ptr);
  508.           }
  509.           break;                        /* ...V1.1 */
  510.           case CDF_BYTE:
  511.           {
  512.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  513.                           int1_ptr);
  514.           
  515.             free(int1_ptr);
  516.           }
  517.           break;
  518.           case CDF_FLOAT:
  519.           {
  520.            status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  521.                           real4_ptr);
  522.           
  523.             free(real4_ptr);
  524.           }
  525.           break;
  526.           case CDF_DOUBLE:
  527.           {
  528.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  529.                           real8_ptr);
  530.           
  531.             free(real8_ptr);
  532.           }
  533.           break;
  534.           
  535.         }/* end switch */
  536.       }/* end else */
  537.       StatusHandler (status);
  538.       
  539.       len = 0;
  540.       while( *(c_ptr + len) != NULL)
  541.        {
  542.          dummy_ptr = (char *) *(c_ptr +len);
  543.          free(dummy_ptr);
  544.          len++;
  545.        }
  546.  
  547.       cfree(c_ptr);
  548.  
  549.       c_ptr = NULL;
  550.  
  551.       free(str_ptr);
  552.  
  553.       str_ptr = NULL;
  554.       free(index_ptr);
  555.    count++;
  556.   }/* end while */  
  557. }
  558.  
  559.  
  560. /*----------------------------------------------------------------*/
  561.  
  562. void ReadNRVFile(num_values, numdims, var_name, str_len)
  563. long num_values;
  564. long numdims;
  565. char *var_name;
  566. long str_len;/* the string size of the variable */
  567. {
  568.  
  569.    FILE *nfp;
  570.    long offset, diff;
  571.    long count = 0, len, flag, i_flag;
  572.    char *buff, *dummy_ptr, *temp_addr,
  573.    *nrv_fname, *temp_ptr;
  574.  
  575.    long num_index, var_data_type, *index_ptr;
  576.  
  577.    len = strlen(sname) + strlen(".nrv_data");            /* V1.1... */
  578.  
  579.    nrv_fname = (char *) malloc (len + 1);             /* +1 for NUL */
  580.    strcpy(nrv_fname,sname);
  581.  
  582.    /* *(nrv_fname + strlen(sname)); */
  583.  
  584.    strcat(nrv_fname,".nrv");
  585.  
  586.    /* *(nrv_fname + len) = '\0'; */
  587.  
  588.    nfp = fopen(nrv_fname, "r");
  589.    if (nfp == NULL) {
  590.      strcpy (nrv_fname, sname);
  591.      strcat (nrv_fname, ".nrv_data");
  592.      nfp = fopen (nrv_fname, "r");
  593.      if (nfp == NULL) return;          /* no nrv file - go to next variable */
  594.    }                                /* ...V1.1 */
  595.  
  596.    while(!feof(nfp))/* until eof */
  597.     {
  598.      flag = 0;
  599.  
  600.      while((flag != 1)&&(feof(nfp)!=1))/* alos tests if end of f is reached*/
  601.       {
  602.        fgets(obuffer,134, nfp);
  603.  
  604.        len = strlen(obuffer);
  605.        *(obuffer + (len -1)) = '\0';
  606.        buff = TrimBlanks(obuffer);
  607.        
  608.        if(*buff == '\0')
  609.        {
  610.        }
  611.        else if (*buff == '!')
  612.        {
  613.        }
  614.        else if (*buff == '[')
  615.        {
  616.        }
  617.        else if (*buff == '=')
  618.        {
  619.        }
  620.        else if (IsDelimString(buff) == 0)
  621.        {
  622.         /*printf("delim %s\n", buff);*/
  623.        }
  624.        else/* get out of the loop only if the same var name is found */
  625.          {
  626.            buff = ParseDString(buff, *buff);
  627.  
  628.            if(strcmp(str_ptr,var_name)==0)
  629.             {
  630.               /*printf("match made for the var %s\n", var_name);*/
  631.               flag++;
  632.               free(str_ptr);
  633.               str_ptr = NULL;
  634.  
  635.    count = 0;
  636.       
  637.   while(count < num_values)
  638.   {
  639.  
  640.     i_flag = 0;
  641.  
  642.      while(i_flag != 1)
  643.      {
  644.  
  645.        if(fgets(obuffer,134, nfp) == NULL)
  646.        {
  647.          if (mLog) fprintf(stderr,
  648.               "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  649.          DeleteCDF(id);
  650.          ExitBAD;
  651.        }
  652.  
  653.        len = strlen(obuffer);
  654.        *(obuffer + (len -1)) = '\0';
  655.  
  656.        buff = TrimBlanks(obuffer);
  657.   
  658.        switch(*buff)
  659.        {
  660.          case '!':
  661.          break;
  662.          case '\0':
  663.          break;
  664.          default:
  665.            i_flag++;
  666.          break;
  667.        }/* end switch */
  668.       
  669.      }/* end while */
  670.  
  671.      if(*buff != '[')
  672.       {
  673.     if (mLog) {
  674.           fprintf(stderr,"\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  675.           fprintf(stderr,"%s\n",obuffer); 
  676.     }
  677.         ExitBAD;
  678.       }
  679.  
  680.      buff++;/* move past the [ */
  681.    
  682.      buff = TrimBlanks(buff);
  683.  
  684.  
  685.       if((*buff == '\0')||(*buff == '!'))
  686.          buff = ProcessWrapLines(nfp, obuffer,
  687.      "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  688.  
  689.      ParseNumericValue(nfp, buff, ']', 
  690.      "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");/* loaded in str_ptr */
  691.      /*printf("%s\n", str_ptr);*/ 
  692.     
  693.       if(!numdims && !strlen(str_ptr))
  694.       {
  695.          free(str_ptr);
  696.          str_ptr = (char *) malloc(2);/* one for a value one for \0 */
  697.          strcpy(str_ptr, "0");
  698.          num_index = ProcessNumericString();
  699.          num_index--;/* was 1 now 0 */
  700.       }
  701.      else
  702.       {
  703.          num_index = ProcessNumericString();
  704.  
  705.          if(num_index != numdims)
  706.          {
  707.            if (mLog) fprintf(stderr,
  708.                 "\nINCORRECTLY SPECIFIED INDICE FOR NRV DATA\n");
  709.            DeleteCDF(id);
  710.            ExitBAD;
  711.          }
  712.       }
  713.  
  714.        var_data_type = cdf_data_type;/* copy the current type*/ 
  715.        cdf_data_type = CDF_INT4;/* for the array indexes */
  716.  
  717.       TypeConvertString(num_index);  /* int4_ptr has it *//* V1.3 */
  718.  
  719.        cdf_data_type = var_data_type;
  720.  
  721.       index_ptr = (long *) malloc(num_index * sizeof(long));    /* V1.2 */
  722.  
  723.       len = 0;/* index ptr is an array containing the subscripts*/
  724.  
  725.       while( len <= num_index -1 )
  726.        {
  727.          *(index_ptr + len ) = *(int4_ptr + len) - 1;
  728.          len++;/* - 1 because internally the matrix starts at 0 */
  729.        }
  730.  
  731.      /* free the allocated spaces for the NRV variable values */
  732.   
  733.       len = 0;
  734.   
  735.      while(len <= num_index - 1)
  736.        {
  737.         free(int4_ptr + len); 
  738.         len++;
  739.        }
  740.  
  741.       len = 0;
  742.       while(*(c_ptr + len) != NULL )
  743.        {
  744.         dummy_ptr = (char *) *(c_ptr + len);
  745.         free(dummy_ptr);
  746.         len++;
  747.        }
  748.  
  749.      cfree(c_ptr);
  750.      c_ptr = NULL;
  751.      free(str_ptr);
  752.      str_ptr = NULL;
  753.  
  754.      buff = strchr(buff, '=');/* look for the = */
  755.      if (buff == 0)
  756.      {
  757.  
  758.        buff = ProcessWrapLines(nfp, obuffer,  
  759.        "\nINCORRECT NRV DATA SPECIFICATION\n");
  760.  
  761.        if(*buff != '=')
  762.        { 
  763.     if (mLog) {
  764.           fprintf(stderr, "\nINCORRECT NRV DATA SPECIFICATION\n");
  765.           fprintf(stderr,"%s\n",obuffer); 
  766.     }
  767.         DeleteCDF(id);
  768.         ExitBAD;
  769.        }
  770.      }
  771.  
  772.      buff++;/* get past the  = */
  773.  
  774.      buff = TrimBlanks(buff);
  775.  
  776.      switch(*buff)
  777.      {
  778.        case '!':
  779.        {
  780.        buff = ProcessWrapLines(nfp, obuffer,  
  781.        "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  782.        }
  783.        break;
  784.        case '\0':
  785.        {
  786.        buff = ProcessWrapLines(nfp, obuffer,  
  787.        "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  788.        }
  789.        break;
  790.        default:
  791.        break;
  792.      }/* end switch */
  793.  
  794. /*****************************/
  795.      if((cdf_data_type == CDF_CHAR)||(cdf_data_type == CDF_UCHAR))
  796.        {
  797.          if(*buff != '{')
  798.            {
  799.          if (mLog) {
  800.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  801.                fprintf(stderr,"%s\n",obuffer); 
  802.          }
  803.              DeleteCDF(id); 
  804.              ExitBAD;
  805.            }
  806.  
  807.           buff++;
  808.  
  809.           buff = TrimBlanks(buff);
  810.  
  811.  
  812.           if((*buff == '\0')||(*buff == '!'))
  813.             buff = ProcessWrapLines(nfp, obuffer,
  814.             "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  815.  
  816.           str_ptr = NULL;
  817.            ParseValue(nfp, buff, *buff,
  818.            "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  819.  
  820.           c_ptr = (char **) calloc(2, sizeof(char *));
  821.  
  822.           len = strlen(str_ptr);
  823.           /*printf("%s\n", str_ptr);*/
  824.           *(c_ptr) = (char *) malloc(len + 6); 
  825.  
  826.           strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  827.  
  828.           dummy_ptr = (char *) *c_ptr;
  829.  
  830.           *(dummy_ptr + len) = '\0';
  831.  
  832.           *(c_ptr + 1) = NULL;
  833.  
  834.        }
  835.      else if((cdf_data_type == CDF_EPOCH)&&(strchr(buff, ':')))
  836.         {
  837.     temp_addr = buff;/* start of the variable */
  838.  
  839.        len = StringTraverse(buff);
  840.  
  841.        buff = buff + len;/* get past the variable value */
  842.  
  843.           buff = TrimBlanks(buff);       
  844.  
  845.           switch (*buff)
  846.           {
  847.             case '!':
  848.             {
  849.          if (mLog) {
  850.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  851.                fprintf(stderr,"%s\n",obuffer); 
  852.          }
  853.              DeleteCDF(id); 
  854.             ExitBAD;
  855.             }
  856.             break;
  857.             case '\0':
  858.             {
  859.          if (mLog) {
  860.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  861.                fprintf(stderr,"%s\n",obuffer); 
  862.          }
  863.              DeleteCDF(id); 
  864.              ExitBAD;
  865.             }
  866.             break;
  867.             default:
  868.             break;
  869.           }/* end switch */
  870.  
  871.  
  872.           len = StringTraverse(buff);/* the second string */
  873.           buff = buff + len;
  874.            
  875.           buff = TrimBlanks(buff);
  876.  
  877.           switch(*buff)
  878.           {
  879.             case '!':
  880.             break;
  881.             case '\0':
  882.             break;
  883.             default:
  884.             {
  885.          if (mLog) {
  886.                fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  887.                fprintf(stderr,"%s\n",obuffer); 
  888.          }
  889.              DeleteCDF(id);
  890.              ExitBAD;
  891.             }
  892.             break;
  893.           }/* end switch */
  894.           buff--;/* get before it */
  895.  
  896.       len = buff - temp_addr + 1;/* lenghth of string to be copied */
  897.  
  898.       str_ptr = (char *) malloc(len + 1 + 6);/* copy it into str_ptr */
  899.  
  900.       strncpy(str_ptr, temp_addr, len);
  901.       
  902.       *(str_ptr + len) = '\0';
  903.  
  904.       c_ptr = (char **) calloc(2, sizeof( char *));/* 2 pointers */
  905.  
  906.       *(c_ptr) = (char *) malloc(len + 6);
  907.  
  908.       strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  909.  
  910.       dummy_ptr = (char *) *c_ptr;
  911.  
  912.       *(dummy_ptr + len) = '\0';
  913.  
  914.       *(c_ptr + 1) = NULL;
  915.         }
  916.        else
  917.         {
  918.     temp_addr = buff;/* start of the variable */
  919.  
  920.        len = StringTraverse(buff);
  921.  
  922.        buff = buff + len;/* get past the variable value */
  923.  
  924.           buff = TrimBlanks(buff);
  925.  
  926.           switch(*buff)
  927.           {
  928.             case '!':
  929.             break;
  930.             case '\0':
  931.             break;
  932.             default:
  933.             {
  934.           if (mLog) {
  935.                 fprintf(stderr, "\nINCORRECTLY SPECIFIED NRV DATA VALUE\n");
  936.                 fprintf(stderr,"%s\n",obuffer); 
  937.           }
  938.               DeleteCDF(id);
  939.               ExitBAD;
  940.             }
  941.             break;
  942.           }/* end switch */
  943.           buff--;/* get to the previous char */
  944.  
  945.       len = buff - temp_addr + 1;/* lenghth of string to be copied */
  946.  
  947.       str_ptr = (char *) malloc(len + 1 + 6);/* copy it into str_ptr */
  948.  
  949.       strncpy(str_ptr, temp_addr, len);
  950.       
  951.       *(str_ptr + len) = '\0';
  952.  
  953.       c_ptr = (char **) calloc(2, sizeof( char *));/* 2 pointers */
  954.  
  955.       *(c_ptr) = (char *) malloc(len + 6);
  956.  
  957.       strcpy(*c_ptr, str_ptr);/* copy it into 1 */
  958.  
  959.       dummy_ptr = (char *) *c_ptr;
  960.  
  961.       *(dummy_ptr + len) = '\0';
  962.  
  963.       *(c_ptr + 1) = NULL;
  964.  
  965.         }/* end else */
  966. /****************************/
  967.  
  968.       
  969.      if((cdf_data_type == CDF_CHAR)||(cdf_data_type == CDF_UCHAR))
  970.       {
  971.         /*printf("%s\n", str_ptr);*/
  972.  
  973.         /* V1.3 */
  974.  
  975.        /* assumption - no ! terminates the nrv data - only '\0' */
  976.         if(strlen(str_ptr) <= str_len)
  977.          {
  978.           if(strlen(str_ptr) < str_len)  
  979.           {
  980.             diff = str_len - strlen(str_ptr);
  981.             temp_ptr =  (char *)malloc(str_len + 1 + 6);
  982.             strcpy(temp_ptr, str_ptr); 
  983.  
  984.             offset = strlen(str_ptr); 
  985.  
  986.             while(diff != 0)
  987.             {
  988.               *(temp_ptr + offset) = ' ';
  989.               diff--;
  990.               offset++;
  991.             }
  992.  
  993.             *(temp_ptr + (str_len + 1)) = '\0';
  994.  
  995.             free(str_ptr);
  996.            
  997.             str_ptr = (char *)malloc(str_len + 1 + 6);
  998.             strcpy(str_ptr, temp_ptr);
  999.             *(str_ptr + (str_len + 1)) = '\0';
  1000.             free(temp_ptr);
  1001.            }
  1002.           status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1003.                               str_ptr );
  1004.          }
  1005.         else
  1006.           {
  1007.        if (mLog) {           
  1008.              fprintf(stderr, "\nSTRING SIZE AND NRV VALUE DON'T MATCH\n");
  1009.              fprintf(stderr, "NRV VALUE TRUNCATED\n");
  1010.        }
  1011.            status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1012.                               str_ptr );
  1013.           }
  1014.       }
  1015.      else
  1016.      { 
  1017.  
  1018.       if(!strncmp(var_name,"EPOCH",5))/* V 1.4 */
  1019.           TypeConvertString(1);  /* only one value */
  1020.         else
  1021.           TypeConvertString(1);  /* only one value non epoch */
  1022.  
  1023.       
  1024.         
  1025.         len = 0;
  1026.         while(len <= num_index - 1)
  1027.         {
  1028.          /*printf("index %ld\n", *(index_ptr + len));*/
  1029.          len++;
  1030.         }
  1031.         switch(cdf_data_type)
  1032.         {
  1033.           case CDF_INT1:
  1034.           {
  1035.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1036.                           int1_ptr);
  1037.           
  1038.             free(int1_ptr);
  1039.           }
  1040.           break;
  1041.           case CDF_INT2:
  1042.           {
  1043.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1044.                           int2_ptr);
  1045.           
  1046.             free(int2_ptr);
  1047.           }
  1048.           break;
  1049.           case CDF_INT4:
  1050.           {
  1051.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1052.                           int4_ptr);
  1053.           
  1054.             free(int4_ptr);
  1055.           }
  1056.           break;
  1057.           case CDF_UINT1:
  1058.           {
  1059.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1060.                           uint1_ptr);
  1061.           
  1062.             free(uint1_ptr);
  1063.           }
  1064.           break;
  1065.           case CDF_UINT2:
  1066.           {
  1067.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1068.                           uint2_ptr);
  1069.           
  1070.             free(uint2_ptr);
  1071.           }
  1072.           break;
  1073.           case CDF_UINT4:
  1074.           {
  1075.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1076.                           uint4_ptr);
  1077.           
  1078.             free(uint4_ptr);
  1079.           }
  1080.           break;
  1081.           case CDF_REAL4:
  1082.           {
  1083.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1084.                           real4_ptr);
  1085.           
  1086.             free(real4_ptr);
  1087.           }
  1088.           break;
  1089.           case CDF_REAL8:
  1090.           {
  1091.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1092.                           real8_ptr);
  1093.              /*printf("%e\n", *real8_ptr);*/
  1094.             free(real8_ptr);
  1095.           }
  1096.           break;
  1097.           case CDF_EPOCH:                    /* V1.1... */
  1098.           {
  1099.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1100.                           real8_ptr);
  1101.             free(real8_ptr);
  1102.           }
  1103.           break;                        /* ...V1.1 */
  1104.           case CDF_BYTE:
  1105.           {
  1106.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1107.                           int1_ptr);
  1108.           
  1109.             free(int1_ptr);
  1110.           }
  1111.           break;
  1112.           case CDF_FLOAT:
  1113.           {
  1114.            status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1115.                           real4_ptr);
  1116.           
  1117.             free(real4_ptr);
  1118.           }
  1119.           break;
  1120.           case CDF_DOUBLE:
  1121.           {
  1122.             status = CDFvarPut(id, cdf_var_num, (long) 0,index_ptr,
  1123.                           real8_ptr);
  1124.           
  1125.             free(real8_ptr);
  1126.           }
  1127.           break;
  1128.           
  1129.         }/* end switch */
  1130.       }/* end else */
  1131.       StatusHandler (status);
  1132.       
  1133.       len = 0;
  1134.       while( *(c_ptr + len) != NULL)
  1135.        {
  1136.          dummy_ptr = (char *) *( c_ptr +len);
  1137.          free(dummy_ptr);
  1138.          len++;
  1139.        }
  1140.  
  1141.       cfree(c_ptr);
  1142.  
  1143.       c_ptr = NULL;
  1144.  
  1145.       free(str_ptr);
  1146.  
  1147.       str_ptr = NULL;
  1148.       free(index_ptr);
  1149.    count++;
  1150.   }/* end while */
  1151.  
  1152.  
  1153.             }
  1154.            else
  1155.             {
  1156.               free(str_ptr);
  1157.               str_ptr = NULL;
  1158.             }
  1159.         
  1160.          }/* end default */
  1161.       }/* end while */
  1162.  
  1163.     }/* end while */
  1164.  
  1165.  
  1166.   fclose(nfp);/* close the file after reaching the end */
  1167.   free(nrv_fname);    
  1168.    
  1169. }
  1170.  
  1171.  
  1172.  
  1173.  
  1174. /*-----------------------------------------------------------------*/
  1175.  
  1176. char *TrimBlanks(aaddr)
  1177. char aaddr[];/* returns a non white space char/ eo string */
  1178.   {
  1179.      char *addr;
  1180.      addr = aaddr;
  1181.      while (*addr != '\0')
  1182.       {
  1183.          switch(*addr)
  1184.          {
  1185.            case ' ':
  1186.              addr++;
  1187.            break;
  1188.            case '\t':
  1189.              addr++;
  1190.            break;
  1191.            default:
  1192.              return(addr);
  1193.            /* break; */        /* Unreachable. */
  1194.          }
  1195.       }
  1196.      return(addr);
  1197.   }
  1198.  
  1199. /*-------------------------------------------------------------------------*/
  1200.  
  1201. int StringTraverse(aaddr)
  1202. char aaddr[];/* returns the length of the string */
  1203.   {
  1204.     char *temp_add, *addr;
  1205.     long len;
  1206.     
  1207.     addr = aaddr;/* for pointer manipulation */
  1208.     
  1209.     temp_add = addr;/* to note the initial position */
  1210.  
  1211.     while((*addr != ' ')&&(*addr != '!')&&(*addr != '\t')&&(*addr != '\0'))
  1212.      addr++;
  1213.  
  1214.  
  1215.     len = addr-temp_add;
  1216.     return(len);
  1217.   }
  1218.  
  1219. /*--------------------------------------------------------------------------*/
  1220.  
  1221. long GetValue(buff, dummy)
  1222. char buff[];/* copies the characters after allocating space*/
  1223. char dummy[];
  1224.   {
  1225.      long ret = 0, len;
  1226.  
  1227.    
  1228.      if((*buff == '!')||(*buff == '\0'))
  1229.        return(ret++);/* incase comment or end of string */
  1230.  
  1231.      len = StringTraverse(buff);/* till white space or '\0' */
  1232.      
  1233.      strncpy(dummy, buff, len);
  1234.      *(dummy + len) = '\0';
  1235.      
  1236.      return(ret);
  1237.   }
  1238.  
  1239. /*-----------------------------------------------------------------*/
  1240.  
  1241. char *ParseDataType(buff, dummy)
  1242. char buff[];/* */
  1243. char dummy[];/* returns the pointer at the following cases */
  1244.  {
  1245.  
  1246.    long flag = 0;
  1247.    char *temp_addr;
  1248.    
  1249.    temp_addr = buff;
  1250.    strcpy(dummy,"            ");
  1251.  
  1252.   
  1253.    while(flag ==0)/* to look till any of the below is encountered */
  1254.    {
  1255.      switch(*buff)
  1256.      {
  1257.       case ' ':
  1258.            {
  1259.             strncpy(dummy, temp_addr, buff-temp_addr);
  1260.             *(dummy + (buff-temp_addr)) = '\0';
  1261.             flag++;
  1262.            }
  1263.       break;
  1264.       case '{':
  1265.            {
  1266.             strncpy(dummy, temp_addr, buff-temp_addr);
  1267.             *(dummy + (buff-temp_addr)) = '\0';
  1268.             flag++;
  1269.            }
  1270.       break;
  1271.       case '\t':
  1272.            {
  1273.             strncpy(dummy, temp_addr, buff-temp_addr  );
  1274.             *(dummy + (buff-temp_addr)) = '\0';
  1275.             flag++;
  1276.            }
  1277.       break;
  1278.       case '!':
  1279.            {
  1280.             strncpy(dummy, temp_addr, buff-temp_addr  );
  1281.             *(dummy + (buff-temp_addr)) = '\0';
  1282.             flag++;
  1283.            }
  1284.       break;
  1285.       case '\0':
  1286.            {
  1287.             strncpy(dummy, temp_addr, buff-temp_addr  );
  1288.             *(dummy + (buff-temp_addr)) = '\0';
  1289.             flag++;
  1290.            }                  
  1291.       break;
  1292.       default:
  1293.         buff++;
  1294.       break;
  1295.      }/* end switch */
  1296.    }/* end while */
  1297.     return(buff);
  1298.  } 
  1299.  
  1300. /*------------------------------------------------------------------*/
  1301.  
  1302. long AnalyseDataType(data_type)
  1303. char data_type[];
  1304. {
  1305.   long len;
  1306.  
  1307.   strupper(data_type);
  1308.   len = strlen(data_type);
  1309.   *(data_type + (len+1)) = '\0';
  1310.  
  1311.   if(strcmp(data_type,"CDF_INT1")==0)
  1312.    cdf_data_type = CDF_INT1;
  1313.   else if (strcmp(data_type,"CDF_INT2")==0)
  1314.   cdf_data_type = CDF_INT2;
  1315.   else if (strcmp(data_type,"CDF_INT4")==0)
  1316.   cdf_data_type = CDF_INT4;
  1317.   else if (strcmp(data_type,"CDF_UINT1")==0)
  1318.   cdf_data_type = CDF_UINT1;
  1319.   else if (strcmp(data_type,"CDF_UINT2")==0)
  1320.   cdf_data_type = CDF_UINT2;
  1321.   else if (strcmp(data_type,"CDF_UINT4")==0)
  1322.   cdf_data_type = CDF_UINT4;
  1323.   else if (strcmp(data_type,"CDF_REAL4")==0)
  1324.   cdf_data_type = CDF_REAL4;
  1325.   else if (strcmp(data_type,"CDF_REAL8")==0)
  1326.   cdf_data_type = CDF_REAL8;
  1327.   else if (strcmp(data_type,"CDF_CHAR")==0)
  1328.   cdf_data_type = CDF_CHAR;
  1329.   else if (strcmp(data_type,"CDF_UCHAR")==0)
  1330.   cdf_data_type = CDF_UCHAR;
  1331.   else if (strcmp(data_type,"CDF_BYTE")==0)
  1332.   cdf_data_type = CDF_BYTE;
  1333.   else if (strcmp(data_type,"CDF_FLOAT")==0)
  1334.   cdf_data_type = CDF_FLOAT;
  1335.   else if (strcmp(data_type,"CDF_DOUBLE")==0)
  1336.   cdf_data_type = CDF_DOUBLE;
  1337.   else if (strcmp(data_type,"CDF_EPOCH")==0)
  1338.   cdf_data_type = CDF_EPOCH;
  1339.   else
  1340.    {
  1341.      if (mLog) fprintf(stderr, "Unrecognized Data Type: %s\n", data_type );
  1342.      DeleteCDF(id);/* assumes that the id is a global var*/
  1343.      ExitBAD;
  1344.    }
  1345.    return(cdf_data_type);
  1346. }
  1347.  
  1348. /*-------------------------------------------------------------------*/
  1349.  
  1350. int ParseValue(fp, buffer, delim, mess)
  1351. FILE *fp;
  1352. char buffer[];/* buffer starting with the delim */
  1353. char delim;
  1354. char mess[];/* the error message */
  1355. {
  1356.   char *temp_addr, *temp_ptr, *buff;
  1357.   long dum, hdr_flag , len;
  1358.  
  1359.  
  1360.   /*strcpy(lbuffer, buffer);*//* for error messages */
  1361.  
  1362.   buffer++;/* get past the delimiter */
  1363.   
  1364.   if(*buffer == '\0')
  1365.   {
  1366.     if (mLog) {
  1367.       fprintf(stderr, "%s\n", mess);
  1368.       fprintf(stderr,"%s\n", obuffer); 
  1369.     }
  1370.     DeleteCDF(id);/* assumes that the id is a global var*/
  1371.     ExitBAD;
  1372.   }
  1373.  
  1374.   temp_addr = buffer;
  1375.  
  1376.   buffer = ValueTraverse(buffer, delim);/* get to the end dilimiter */
  1377.   
  1378.   switch(*buffer)
  1379.    {
  1380.     case '\0':/* in case no delimiter is found at the end */
  1381.     {
  1382.     if (mLog) {
  1383.       fprintf(stderr,"%s\n", mess);
  1384.       fprintf(stderr, "%s\n",obuffer);
  1385.     }
  1386.      DeleteCDF(id);/* assumes that the id is a global var*/
  1387.      ExitBAD;
  1388.     }
  1389.     break;
  1390.     default:
  1391.     {
  1392.     if(str_ptr == NULL)
  1393.       {
  1394.  
  1395.        str_ptr = (char *) malloc(buffer-temp_addr + 2);
  1396.                         /* create space for value 
  1397.                            excluding the delimiter */
  1398.        strncpy(str_ptr, temp_addr, buffer-temp_addr);
  1399.        *(str_ptr + (buffer-temp_addr)) = '\0';
  1400.       }
  1401.     else
  1402.       {
  1403.         /*temp_ptr = str_ptr;*/
  1404.  
  1405.         temp_ptr = (char *) malloc(strlen(str_ptr) + 1 + 1);
  1406.  
  1407.         strcpy(temp_ptr, str_ptr);
  1408.         *(temp_ptr + strlen(str_ptr)) = '\0';
  1409.         free(str_ptr);
  1410.  
  1411.         str_ptr = (char *)malloc(strlen(temp_ptr) + buffer-temp_addr + 1);
  1412.  
  1413.         strcpy(str_ptr, temp_ptr);
  1414.         strncat(str_ptr, temp_addr, buffer-temp_addr);
  1415.         *(str_ptr + strlen(temp_ptr) + (buffer-temp_addr)) = '\0';
  1416.         free(temp_ptr);
  1417.       }
  1418.     ++buffer;/* get past the delimiter */
  1419.  
  1420.     buffer = TrimBlanks(buffer);
  1421.  
  1422.     if((*buffer == '\0')||(*buffer == '!'))
  1423.      {
  1424.       buffer = ProcessWrapLines( fp, obuffer,
  1425.        mess);/*  */
  1426.  
  1427.      if(*buffer != '}')
  1428.        {
  1429.     if (mLog) {
  1430.           fprintf(stderr,"%s\n", mess);
  1431.           fprintf(stderr, "%s\n", obuffer );
  1432.     }
  1433.         DeleteCDF(id);/* assumes that the id is a global var*/
  1434.         ExitBAD;
  1435.        }
  1436.        }
  1437.     
  1438.     switch(*buffer)/* assume that a dash  follows a delimiter */
  1439.      {
  1440.        case '\0':
  1441.       {
  1442.        if (mLog) {
  1443.          fprintf(stderr,"%s\n", mess);
  1444.          fprintf(stderr, "%s\n", obuffer );
  1445.        }
  1446.         DeleteCDF(id);/* assumes that the id is a global var*/
  1447.         ExitBAD;
  1448.        }
  1449.        break;
  1450.        case '}':
  1451.        {
  1452.          ++buffer;/* get past the brace */
  1453.          buffer = TrimBlanks(buffer);
  1454.  
  1455.         switch(*buffer)/* char after the brace */
  1456.          {
  1457.           case '.':/* new attribute next */
  1458.           {
  1459.             buffer++;
  1460.  
  1461.             buffer = TrimBlanks(buffer);/* get past the ; */
  1462.             
  1463.             switch(*buffer)
  1464.              {
  1465.                case '!':
  1466.                {
  1467.                 dum = 1;
  1468.                 return(dum);/* return at end delimiter */
  1469.                }
  1470.  
  1471.                case '\0':
  1472.                {
  1473.                 dum = 1;
  1474.                 return(dum);/* return at end delimiter */
  1475.                 }
  1476.  
  1477.                default:
  1478.               {
  1479.             if (mLog) {
  1480.                   fprintf(stderr, "%s\n", mess);
  1481.                   fprintf(stderr, "%s\n", obuffer);
  1482.         }
  1483.                 DeleteCDF(id);/* assumes that the id is a global var*/
  1484.                 ExitBAD;
  1485.                }
  1486.                break;
  1487.              }/* end switch */
  1488.           }
  1489.           break;
  1490.           case '!':/* have to search next lines */
  1491.           {
  1492.              dum = 0;
  1493.              return(dum);
  1494.            }
  1495.  
  1496.           case '\0':
  1497.           {
  1498.              dum = 0;
  1499.              return(dum);
  1500.           }
  1501.  
  1502.           default:/* unrecognizable character found after } */
  1503.           {
  1504.         if (mLog) {
  1505.               fprintf(stderr, "%s\n", mess);
  1506.               fprintf(stderr, "%s\n", obuffer);
  1507.         }
  1508.             DeleteCDF(id);/* assumes that the id is a global var*/
  1509.             ExitBAD;
  1510.           }
  1511.           break;
  1512.          }/* end switch */         
  1513.        }
  1514.        break;
  1515.        case '-':
  1516.        {
  1517.          ++buffer;/* get past the - */
  1518.          buffer = TrimBlanks(buffer);
  1519.          switch(*buffer)
  1520.          {
  1521.           case '\0':/* continue in the next line */
  1522.           {
  1523.            hdr_flag = 0;
  1524.            while(hdr_flag != 1)
  1525.            {
  1526.             if(fgets(obuffer, 134, fp)==NULL)
  1527.               {
  1528.         if (mLog) fprintf(stderr,"%s\n", mess);
  1529.                 DeleteCDF(id);/* assumes that the id is a global var*/
  1530.                 ExitBAD;
  1531.               }
  1532.             len = strlen(obuffer);
  1533.             obuffer[len-1] = '\0';
  1534.             buff = TrimBlanks(obuffer);
  1535.  
  1536.             switch (*buff)
  1537.             {
  1538.               case '\0':
  1539.               break;
  1540.               case '!':
  1541.               break;
  1542.               default:
  1543.               hdr_flag++;
  1544.               break;
  1545.             }/* end switch */
  1546.            }/* end while */
  1547.            dum = ParseValue(fp, buff, *buff, mess);
  1548.           }
  1549.           break;
  1550.           case '!':/* continue in the next line */
  1551.           {
  1552.            hdr_flag = 0;
  1553.            while(hdr_flag != 1)
  1554.            {
  1555.             if(fgets(obuffer, 134, fp)==NULL)
  1556.               {
  1557.                 if (mLog) fprintf(stderr,"%s\n", mess);
  1558.                 DeleteCDF(id);/* assumes that the id is a global var*/
  1559.                 ExitBAD;
  1560.               }
  1561.             len = strlen(obuffer);
  1562.             obuffer[len-1] = '\0';
  1563.             buff = TrimBlanks(obuffer);
  1564.  
  1565.             switch (*buff)
  1566.             {
  1567.               case '\0':
  1568.               break;
  1569.               case '!':
  1570.               break;
  1571.               default:
  1572.               hdr_flag++;
  1573.               break;
  1574.             }/* end switch */
  1575.            }/* end while */
  1576.            dum = ParseValue(fp, buff, *buff, mess);
  1577.           }
  1578.           break;
  1579.           default:
  1580.           {
  1581.         if (mLog) {
  1582.               fprintf(stderr, "%s\n", mess);
  1583.               fprintf(stderr, "%s\n",obuffer); 
  1584.         }
  1585.             DeleteCDF(id);/* assumes that the id is a global var*/
  1586.             ExitBAD;
  1587.           }
  1588.           break;
  1589.          }/* end switch */
  1590.        }
  1591.        break;
  1592.        default:
  1593.       {
  1594.         if (mLog) {
  1595.          fprintf(stderr, "%s\n", mess);
  1596.          fprintf(stderr, "%s\n", obuffer);
  1597.         }
  1598.         DeleteCDF(id);/* assumes that the id is a global var*/
  1599.         ExitBAD;
  1600.        }
  1601.        break;
  1602.      }/* end switch */
  1603.  
  1604.      
  1605.     }
  1606.     break;
  1607.    }/* end switch */
  1608.  
  1609. return dum;    /* I'm not sure what should be returned, J Love. */
  1610. }
  1611.  
  1612. /*-------------------------------------------------------------------*/
  1613.  
  1614. char *ValueTraverse(addr, delim)
  1615. char addr[];/* traverse the value till end of string , or the delim */
  1616. char delim;
  1617. {
  1618.   
  1619.     
  1620.  
  1621.     while((*addr != delim)&&(*addr != '\0'))
  1622.      addr++;
  1623.  
  1624.     return(addr);
  1625.   
  1626. }
  1627.  
  1628. /*------------------------------------------------------------------*/
  1629.  
  1630. char *ParseDString(addr, delim)
  1631. char addr[];/* address of the string starting at the delimiter */
  1632. char delim;
  1633. {
  1634.     char  *temp_addr;
  1635.  
  1636.  
  1637.     temp_addr = addr;/* addr of 1 delimiter */
  1638.  
  1639.     addr++;/* move by one */
  1640.  
  1641.     while((*addr != delim)&&(*addr != '\0'))
  1642.       addr++;
  1643.     
  1644.     switch (*addr)
  1645.      {
  1646.        case '\0':
  1647.        {
  1648.      if (mLog) {
  1649.            fprintf(stderr,"%s\n", "INCORRECTLY DELIMITED STRING\n");
  1650.            fprintf(stderr, "%s\n", temp_addr);
  1651.      }
  1652.          DeleteCDF(id);/* assumes that the id is a global var*/
  1653.          ExitBAD;
  1654.        }
  1655.        break;
  1656.        default:
  1657.        {
  1658.         str_ptr = (char *)malloc((addr-1)-(temp_addr+1) + 2);/* space for 
  1659.                                   the string without delimiters */
  1660.  
  1661.         strncpy(str_ptr, temp_addr + 1, (addr-temp_addr-1));
  1662.         *(str_ptr + (addr - temp_addr -1)) = '\0';
  1663.        }
  1664.        break;
  1665.      }/* end switch */
  1666.   
  1667.      return(addr);
  1668. }
  1669.  
  1670. /*-------------------------------------------------------------------*/
  1671.  
  1672. int ParseNumericValue(fp,buff, termin, mess)
  1673. /* starts at char after termin
  1674.             and goes on till term (} or ]) is reached*/
  1675.            /* this string is in str_ptr */
  1676. FILE *fp;
  1677. char buff[];/* a non white space - can't be a ! */
  1678. char termin;/* the terminating char */
  1679. /*char lbuffer[];*//* used in a special case  for NRV*/
  1680. char mess[];/* the error message */
  1681. {
  1682.  
  1683.   char *temp_addr, *temp_ptr;/* lbuffer[134];*/
  1684.   long ret, flag, len, dummy;
  1685.  
  1686.   temp_addr = buff;
  1687.  
  1688.   buff = NumericValueTraverse(fp, buff, termin, &ret, obuffer, mess);
  1689.  
  1690. /* returns the address of the  last useful char of the string */
  1691.  
  1692.   if(str_ptr ==NULL)
  1693.   {
  1694.    str_ptr = (char *)malloc(buff-temp_addr+3);/* create space for value*/
  1695.        
  1696.    strncpy(str_ptr, temp_addr, buff-temp_addr+1);/* copy it */
  1697.  
  1698.    *(str_ptr + (buff-temp_addr + 1)) = '\0';
  1699.   }
  1700.   else
  1701.   {
  1702.    temp_ptr = (char *) malloc(strlen(str_ptr) + 3);
  1703.  
  1704.    strcpy(temp_ptr, str_ptr);
  1705.  
  1706.    *(temp_ptr + strlen(str_ptr)) = '\0';
  1707.  
  1708.    free(str_ptr);
  1709.  
  1710.    str_ptr = (char *)malloc(strlen(temp_ptr) + buff-temp_addr + 3);
  1711.  
  1712.    strcpy(str_ptr, temp_ptr);
  1713.    strncat(str_ptr, temp_addr, buff - temp_addr+1);
  1714.    *(str_ptr + (strlen(temp_ptr) + buff-temp_addr+1)) = '\0';
  1715.    free(temp_ptr);
  1716.  
  1717.    }
  1718.  
  1719.    switch(ret)
  1720.    {
  1721.       case 0:/* more seeks needed */
  1722.       {
  1723.          flag = 0;
  1724.         while(flag == 0)
  1725.         {
  1726.           if(fgets(obuffer, 134, fp) == NULL)
  1727.            {
  1728.             if (mLog) fprintf(stderr, "%s\n", mess);
  1729.             DeleteCDF(id);/* assumes that the id is a global var*/
  1730.             ExitBAD;
  1731.            } 
  1732.           
  1733.            len = strlen(obuffer);
  1734.            *(obuffer + (len-1)) = '\0';
  1735.            buff = TrimBlanks(obuffer);
  1736.  
  1737.            switch (*buff)
  1738.            {
  1739.             case ' ':
  1740.             break;
  1741.             case '\0':
  1742.             break;
  1743.             case '!':
  1744.             break;
  1745.             default:
  1746.              flag++;
  1747.             break;
  1748.            }/* end switch */
  1749.         }/* end while */
  1750.  
  1751.         dummy = ParseNumericValue(fp,buff, termin, mess);
  1752.                         
  1753.       }
  1754.       break;
  1755.       case 1:/*no more seeks but no . encountered*/
  1756.       {
  1757.         dummy = 0;
  1758.         return(dummy);
  1759.       }
  1760.  
  1761.       case 2:/* no more seeks and . encountered */
  1762.       {
  1763.         dummy = 1;
  1764.         return(dummy);
  1765.       }
  1766.    }/* end switch */
  1767.  
  1768. return(dummy);    /* I'm not sure what to return, J Love */
  1769. }
  1770.  
  1771. /*---------------------------------------------------------------------*/
  1772.  
  1773. char *NumericValueTraverse(fp, buff, termin, ret, buffer, mess)
  1774. FILE *fp;
  1775. char buff[];/* given a nmeric string, goes on till the end useful char 
  1776.                and returns it */
  1777. char termin;
  1778. long *ret;
  1779. char buffer[];
  1780. char mess[];
  1781. {
  1782.  
  1783.   char *temp_addr, dbuffer[134];
  1784.   long flag, dummy;
  1785.   long c_flag = 0;    /* J Love, 26-Feb-92 */
  1786.  
  1787.   flag = 0;
  1788.  
  1789.   while(flag != 1)
  1790.   {
  1791.     buff = TrimBlanks(buff);
  1792.  
  1793.     if(*buff == termin)/* either a } or a ] */
  1794.       {
  1795.        if(c_flag == 1)/* previous char encountered was a , */
  1796.             {
  1797.           if (mLog) {
  1798.                 fprintf(stderr, "%s", mess);
  1799.                 fprintf(stderr, "%s\n", buffer);
  1800.           }
  1801.               DeleteCDF(id);/* assumes that the id is a global var*/
  1802.               ExitBAD;
  1803.             }
  1804.            else
  1805.             {
  1806.               if(c_flag != -1)
  1807.                  temp_addr = buff;
  1808.  
  1809.               temp_addr--;/* get before the }*/
  1810.               buff++;/* get past the } */
  1811.               buff = TrimBlanks(buff);
  1812.  
  1813.               switch(*buff)/* to check the char after the brace */
  1814.               {
  1815.                 case '!':
  1816.                  {
  1817.                   dummy = 1;
  1818.                   *ret = dummy;
  1819.                   /*strcpy(buffer, dbuffer);*/
  1820.                   return(temp_addr);
  1821.                  }
  1822.  
  1823.                 case '\0':
  1824.                  {
  1825.                    dummy = 1;
  1826.                    *ret = dummy;
  1827.                   /*strcpy(buffer, dbuffer);*/
  1828.                    return(temp_addr);
  1829.                  }
  1830.  
  1831.                 case '.':
  1832.                  {
  1833.                    dummy = 2;
  1834.                    *ret = dummy;
  1835.                   /*strcpy(buffer, dbuffer);*/
  1836.                    return(temp_addr);
  1837.                  }
  1838.                 default:
  1839.                 {
  1840.                   if(termin == '}')
  1841.                   {
  1842.            if (mLog) {
  1843.                      fprintf(stderr, "%s", mess);
  1844.                      fprintf(stderr, "%s\n", buffer);
  1845.            }
  1846.                    DeleteCDF(id);/* assumes that the id is a global var*/
  1847.                    ExitBAD;
  1848.                   }
  1849.                   else/* if ] you can have char after */
  1850.                   {
  1851.                    dummy = 1;
  1852.                    *ret = dummy;
  1853.                   /*strcpy(buffer, dbuffer);*/
  1854.                    return(temp_addr);
  1855.                   }
  1856.                 }
  1857.                 break;
  1858.               }/* end switch */
  1859.             }/* end else */
  1860.       }/* end else if */
  1861.  
  1862.      else if(*buff == '!')
  1863.       {
  1864.         if(c_flag == 1)/* have to read the next line */
  1865.           {
  1866.               buff--;/* get before the ! */
  1867.               dummy = 0;
  1868.               *ret = dummy;
  1869.               return(buff);
  1870.           }
  1871.         else/* check if the next char is '{' */
  1872.            {
  1873.  
  1874.              temp_addr = buff;/* used at the next stage */  
  1875.              buff = ProcessWrapLines( fp, dbuffer,mess); 
  1876.               
  1877.  
  1878.              if(*buff != termin)/* unknown char */ 
  1879.               {
  1880.          if (mLog) {
  1881.                    fprintf(stderr, "%s", mess);
  1882.                    fprintf(stderr, "%s\n", buffer);
  1883.          }
  1884.                  DeleteCDF(id);
  1885.                  ExitBAD;
  1886.               }
  1887.  
  1888.               c_flag = -1;/* special value  */
  1889.            }
  1890.       }/* end else if */
  1891.  
  1892.     else if (*buff == '\0')
  1893.       {  
  1894.          if(c_flag == 1)/* have to read the next line */
  1895.             {
  1896.               buff--;/* get before the \0 */
  1897.               dummy = 0;
  1898.               *ret = dummy;
  1899.               return(buff);
  1900.             }
  1901.            else/* check if the next char is '{' */
  1902.            {
  1903.              temp_addr = buff;/* used at the next stage */  
  1904.              buff = ProcessWrapLines(fp, dbuffer, mess);
  1905.            
  1906.              /* dbuffer is a dummy buffer used to prevent temp_address
  1907.              getting changed if buffer is used here */
  1908.  
  1909.              if(*buff != termin)/* unknown char */ 
  1910.               {
  1911.          if (mLog) {
  1912.                    fprintf(stderr, "%s", mess);
  1913.                    fprintf(stderr, "%s\n", buffer);
  1914.          }
  1915.                  DeleteCDF(id);
  1916.                  ExitBAD;
  1917.               }
  1918.  
  1919.               c_flag = -1;/* special value  */
  1920.            }
  1921.       }/* end else if */
  1922.  
  1923.     else if (*buff == ',')
  1924.       {
  1925.         c_flag = 1;
  1926.         buff++;/* get past it */
  1927.       }/* end else if */
  1928.  
  1929.     else
  1930.       {
  1931.         buff++;/* get past the current char */
  1932.         c_flag = 0;/* means that last char encountered is not , */
  1933.       }
  1934.  
  1935.   }/* while */
  1936.  
  1937. return NULL;    /* Not sure what to return, J Love. */
  1938. }
  1939.  
  1940. /*---------------------------------------------------------------------*/
  1941.  
  1942. long ProcessNumericString()
  1943. {
  1944.    long num_commas;
  1945.  
  1946.    num_commas = CountCommas();
  1947.  
  1948.    c_ptr = (char **) calloc(num_commas+2, sizeof( char *));
  1949.                        /* an array of ptrs */
  1950.  
  1951.    PlaceValues ();
  1952.  
  1953.    return(num_commas + 1);/* the number of values in the array */
  1954.             
  1955. }
  1956.  
  1957. /*------------------------------------------------------------------------*/
  1958.  
  1959. long CountCommas()
  1960. {
  1961.    char *buff;
  1962.    long num;
  1963.  
  1964.    buff = str_ptr;
  1965.   
  1966.    num = 0;
  1967.  
  1968.    while(*buff != '\0')
  1969.    {
  1970.      switch(*buff)
  1971.      {
  1972.        case ',':
  1973.         {
  1974.          num++;
  1975.          buff++;
  1976.         }
  1977.        break;
  1978.        default:
  1979.           buff++;
  1980.        break;
  1981.      }/* end switch */
  1982.    }/* end while */
  1983.  
  1984.    return(num);
  1985. }
  1986.  
  1987. /*---------------------------------------------------------------------*/
  1988.  
  1989. void PlaceValues (/*number*/)
  1990. /*long number;*/ /* number of values to be placed - includes the NULL at end */
  1991. {
  1992.  
  1993.    char *buff, *temp_addr, *dummy;
  1994.    long index =0, flag;
  1995.  
  1996.    buff = str_ptr;
  1997.   
  1998.    temp_addr = str_ptr;
  1999.    
  2000.    flag = 0;
  2001.  
  2002.    while(flag == 0) 
  2003.   {
  2004.  
  2005.    switch(*buff)/* already made sure that no ! in between ,, */
  2006.    {
  2007.      case ',':
  2008.         {
  2009.           if((buff-temp_addr) != 0)
  2010.           {
  2011.             *(c_ptr + index) = (char *) malloc(buff - temp_addr + 2);
  2012.  
  2013.             strncpy(*(c_ptr + index), temp_addr, buff - temp_addr);
  2014.              /* c_ptr[index] contains the pointer to the string */
  2015.             
  2016.             dummy = *(c_ptr + index);
  2017.  
  2018.             *(dummy + (buff-temp_addr)) = '\0'; 
  2019.  
  2020.             buff++;/* get past the , */
  2021.             buff = TrimBlanks(buff);
  2022.             temp_addr = buff;
  2023.             index++;
  2024.           }
  2025.           else
  2026.           {
  2027.         if (mLog) {
  2028.               fprintf(stderr,"\nINCORRECTLY SPECIFIED NUMERIC VALUE(S)");
  2029.               fprintf(stderr, "%s\n", str_ptr); 
  2030.         }
  2031.             DeleteCDF(id);/* assumes that the id is a global var*/
  2032.             ExitBAD;
  2033.           }
  2034.         }
  2035.      break;
  2036.      case '\0':
  2037.         {
  2038.           if((buff-temp_addr) != 0)
  2039.           {
  2040.             *(c_ptr + index) = (char *) malloc(buff - temp_addr + 2);
  2041.  
  2042.             strncpy(*(c_ptr + index), temp_addr, buff - temp_addr);
  2043.             dummy = *(c_ptr + index);
  2044.  
  2045.             *(dummy + (buff-temp_addr)) = '\0';
  2046.  
  2047.             buff++;/* get past the , */
  2048.             buff = TrimBlanks(buff);
  2049.             temp_addr = buff;
  2050.             index++;
  2051.  
  2052.             flag++;/* exit out of the loop */
  2053.           }
  2054.           else
  2055.           {
  2056.         if (mLog) {
  2057.               fprintf(stderr,"INCORRECTLY SPECIFIED NUMERIC VALUES \n");
  2058.               fprintf(stderr, "%s\n", str_ptr); 
  2059.         }
  2060.             DeleteCDF(id);/* assumes that the id is a global var*/
  2061.             ExitBAD;
  2062.           }
  2063.         }
  2064.      break;
  2065.      default:
  2066.        {
  2067.          buff++;
  2068.        }
  2069.      break;
  2070.    }/* end switch */
  2071.   }/* end while */
  2072.  
  2073.   *(c_ptr + index) = NULL; /** this is the last element of the ptr array */ 
  2074. }
  2075.  
  2076. /*-----------------------------------------------------------------*/
  2077.  
  2078. void ParseVariances(fp,buff, var_array, buffer)
  2079. /* parses the string and */
  2080. FILE *fp;
  2081. char buff[];                   /* places values in a supplied array */
  2082. long var_array[];
  2083. char buffer[];
  2084. {
  2085.   extern long num_dims;
  2086.   long index = 0;
  2087.   long flag = 0;
  2088.  
  2089.  while(flag != 1)
  2090.   {
  2091.   buff = TrimBlanks(buff);
  2092.  
  2093.   switch(*buff)
  2094.   {
  2095.     case '\0':
  2096.     {
  2097.       if((index) != (1 + num_dims))/* 1 for the record variance */
  2098.       {
  2099.          buff = ProcessWrapLines(fp, buffer, 
  2100.          "INCORRECT VARIABLE SPECIFICATION\n");
  2101.       }
  2102.       else
  2103.       {
  2104.         flag++;
  2105.       }
  2106.     }
  2107.     break;
  2108.     case '!':
  2109.     {
  2110.       if((index) != ( 1 + num_dims))
  2111.       {
  2112.          buff = ProcessWrapLines(fp, buffer, 
  2113.          "INCORRECT VARIABLE SPECIFICATION\n");
  2114.       }
  2115.       else
  2116.         flag++;
  2117.     }
  2118.     break;
  2119.     case '.':
  2120.     {
  2121.       if((index) != (1 + num_dims))/* 1 for the record variance */
  2122.        {
  2123.     if (mLog) {
  2124.           fprintf(stderr, "INCORRECT RECORD/DIMENSION VARIANCE \n");
  2125.           fprintf(stderr,"%s\n", buffer);
  2126.     }
  2127.         DeleteCDF(id);/* assumes that the id is a global var*/
  2128.         ExitBAD;
  2129.        }
  2130.       else
  2131.       {
  2132.         buff++;/* get past the . */
  2133.         buff = TrimBlanks(buff);
  2134.       
  2135.         if((*buff != '!')&&(*buff != '\0'))
  2136.         {
  2137.      if (mLog) {
  2138.            fprintf(stderr, "INCORRECT RECORD/DIMENSION VARIANCE  \n");
  2139.            fprintf(stderr, "%s\n", buffer);
  2140.      }
  2141.          DeleteCDF(id);/* assumes that the id is a global var*/
  2142.          ExitBAD;
  2143.         }
  2144.  
  2145.       }/* end else */
  2146.     }
  2147.     break;
  2148.     default:
  2149.     {
  2150.       if((isalpha(*buff))&&(islower(*buff)))
  2151.         *buff = toupper(*buff);/* for standardisation */
  2152.  
  2153.        switch(*buff)
  2154.        {
  2155.          case 'T':
  2156.          {
  2157.           *(var_array + index) = -1;/* VARY */
  2158.           buff++; 
  2159.           index++;
  2160.          }
  2161.          break;
  2162.          case 'F':
  2163.          {
  2164.           *(var_array + index) = 0;/* NOVARY */
  2165.           buff++; 
  2166.           index++;
  2167.          }
  2168.          break;
  2169.          default:/* unrecognizable char */
  2170.          {
  2171.       if (mLog) {
  2172.             fprintf(stderr, "INCORRECT RECORD/DIMENSION VARIANCE \n");
  2173.             fprintf(stderr,"%s\n", buffer);
  2174.       }
  2175.           DeleteCDF(id);/* assumes that the id is a global var*/
  2176.           ExitBAD;
  2177.          }
  2178.          break;
  2179.        }/* end switch */
  2180.     }
  2181.     break;
  2182.   }/* end switch */
  2183.  }/* end while */
  2184. }
  2185.  
  2186. /*--------------------------------------------------------------------*/
  2187.  
  2188. void TypeConvertString(NumValues /*, epoch_flag*/)/* converts the */
  2189.                                 /* array of strings into the appropriate type */
  2190. long NumValues;/* number of string values in the array */
  2191. /* long epoch_flag; */ /* 1 if epoch conversion is to be done 0 otherwise*/
  2192. {
  2193.   
  2194.   char nchar, *s;
  2195.   
  2196.   unsigned char nuchar;
  2197.  
  2198.   short nshort;
  2199.   unsigned short nushort; 
  2200.  
  2201.   long index = 0, test_val, i;
  2202.  
  2203.   float float_val;
  2204.   double double_val;
  2205.   struct EPOCH epoch;
  2206.  
  2207.  
  2208.   switch(cdf_data_type)
  2209.   {
  2210.     case CDF_INT1:
  2211.     {
  2212.  
  2213.        index = 0;
  2214.  
  2215.        int1_ptr = (Schar *) malloc(NumValues*sizeof(Schar));
  2216.  
  2217.        while( index <= NumValues - 1)/* convert & copy the values */
  2218.        {
  2219.          s = *(c_ptr + index);
  2220.  
  2221.          if(*s == '-')/* a negative number */
  2222.          {
  2223.            s++;/* get past */
  2224.            s = TrimBlanks(s);/* to get rid of blank spaces */
  2225.            test_val = -(atoi(s));
  2226.            s = *(c_ptr + index);/* reassign */
  2227.          }
  2228.          else
  2229.            test_val = atoi(s);/* to check its range */
  2230.  
  2231.          if((test_val< -128)||(test_val > 127))
  2232.           {
  2233.        if (mLog)
  2234.              fprintf(stderr,"Numeric value too large for the data type");
  2235.            DeleteCDF(id);/* assumes that the id is a global var*/
  2236.            ExitBAD;
  2237.           }         
  2238.  
  2239.   
  2240.          nchar = 0;
  2241.          
  2242.          if(*s == '-')
  2243.          {
  2244.            s++;/* get past*/
  2245.            s = TrimBlanks(s);/* to eliminate any blanks */
  2246.          }
  2247.  
  2248.          for(i = 0;*(s + i) >= '0'&& *(s + i) <= '9'; ++i)
  2249.            nchar = 10*nchar + *(s + i) - '0';/* terminates if a non numeric
  2250.                                     char or if the value exceeds */
  2251.  
  2252.             if(*(s + i) != '\0')/* a non numeric char or a space*/
  2253.              {
  2254.                s = TrimBlanks(s + i);
  2255.  
  2256.                if(*s != '\0')
  2257.                {
  2258.                  if (mLog) fprintf(stderr, "Incorrectly specified value:%s\n",
  2259.                                   *(c_ptr + index));
  2260.                  DeleteCDF(id);/* assumes that the id is a global var*/
  2261.                   ExitBAD;
  2262.                }
  2263.              }        
  2264.    
  2265.            *(int1_ptr + index) = nchar;/* copy this into the array */
  2266.  
  2267.            
  2268.           s = *(c_ptr + index);/* reassign */
  2269.           if(*s == '-')
  2270.           *(int1_ptr + index) = - *(int1_ptr + index);/* make it negative */
  2271.  
  2272.          index++;/* the next element of that entry */
  2273.  
  2274.        }/* end while */
  2275.     }
  2276.     break;
  2277.     case CDF_INT2:
  2278.     {
  2279.  
  2280.       index = 0;
  2281.  
  2282.        int2_ptr = (short *) malloc(NumValues*sizeof( short));
  2283.  
  2284.        while( index <= NumValues - 1)/* convert & copy the values */
  2285.        {
  2286.          s = *(c_ptr + index);
  2287.  
  2288.          if(*s == '-')/* a negative number */
  2289.          {
  2290.            s++;/* get past */
  2291.            s = TrimBlanks(s);/* to get rid of blank spaces */
  2292.            test_val = -(atoi(s));
  2293.            s = *(c_ptr + index);/* reassign */
  2294.          }
  2295.          else
  2296.            test_val = atoi(s);/* to check its range */
  2297.  
  2298.          if((test_val< -32768)||(test_val > 32767))
  2299.           {
  2300.            if (mLog)
  2301.          fprintf(stderr,"Numeric value too large for the data type");
  2302.            DeleteCDF(id);/* assumes that the id is a global var*/
  2303.            ExitBAD;
  2304.           }         
  2305.  
  2306.   
  2307.          nchar = 0;
  2308.          
  2309.          if(*s == '-')
  2310.          {
  2311.            s++;/* get past*/
  2312.            s = TrimBlanks(s);/* to eliminate any blanks */
  2313.          }
  2314.  
  2315.          nshort = 0;
  2316.          for(i = 0;*(s + i) >= '0'&& *(s + i) <= '9'; ++i)
  2317.            nshort = 10*nshort + *(s + i) - '0';/* terminates if a non numeric
  2318.                                     char or if the value exceeds */
  2319.  
  2320.             if(*(s + i) != '\0')/* a non numeric char or a space*/
  2321.              {
  2322.                s = TrimBlanks(s + i);
  2323.  
  2324.                if(*s != '\0')
  2325.                {
  2326.                  if (mLog) fprintf(stderr, "Incorrectly specified value:%s\n",
  2327.                                   *(c_ptr + index));
  2328.                  DeleteCDF(id);/* assumes that the id is a global var*/
  2329.                   ExitBAD;
  2330.                }
  2331.              }        
  2332.    
  2333.            *(int2_ptr + index) = nshort;/* copy this into the array */
  2334.            
  2335.           s = *(c_ptr + index);/* reassign */
  2336.           
  2337.           if(*s == '-')
  2338.            *(int2_ptr + index) = - *(int2_ptr + index);/* make it negative */
  2339.  
  2340.          index++;/* the next element of that entry */
  2341.  
  2342.        }/* end while */
  2343.     }
  2344.     break;
  2345.     case CDF_INT4:
  2346.     {
  2347.       int4_ptr = (long *) malloc(NumValues*sizeof(long));/* an array of in*/
  2348.    
  2349.        index = 0;
  2350.  
  2351.        while( index <= NumValues - 1)/* convert & copy the values */
  2352.        {
  2353.          s = *(c_ptr + index);
  2354.         
  2355.          if(*s == '-')
  2356.          {
  2357.           s++;
  2358.           s = TrimBlanks(s);
  2359.           *(int4_ptr + index ) = -atoi(s);
  2360.          }
  2361.          else
  2362.           *(int4_ptr + index) = atoi(s);
  2363.          index++;
  2364.        }
  2365.     }
  2366.     break;
  2367.     case CDF_UINT1:
  2368.     {
  2369.        index = 0;
  2370.  
  2371.        uint1_ptr = (Uchar *) malloc(NumValues*sizeof(Uchar));
  2372.                                             /* an array of char*/
  2373.        while( index <= NumValues - 1)/* convert & copy the values */
  2374.        {
  2375.          s = *(c_ptr + index);
  2376.  
  2377.          if(*s == '-')/* a negative number */
  2378.          {
  2379.        if (mLog)
  2380.              fprintf(stderr,"Numeric value too large for this data type\n");
  2381.            DeleteCDF(id);/* assumes that the id is a global var*/
  2382.            ExitBAD;
  2383.          }
  2384.          else
  2385.            test_val = atoi(s);/* to check its range */
  2386.  
  2387.          if((test_val< 0)||(test_val > 255))
  2388.           {
  2389.            if (mLog)
  2390.          fprintf(stderr,"Numeric value too large for the data type");
  2391.            DeleteCDF(id);/* assumes that the id is a global var*/
  2392.            ExitBAD;
  2393.           }         
  2394.  
  2395.   
  2396.          nuchar = 0;
  2397.          
  2398.     
  2399.          for(i = 0;*(s + i) >= '0'&& *(s + i) <= '9'; ++i)
  2400.            nuchar = 10*nuchar + *(s + i) - '0';/* terminates if a non numeric
  2401.                                     char or if the value exceeds */
  2402.  
  2403.             if(*(s + i) != '\0')/* a non numeric char or a space*/
  2404.              {
  2405.                s = TrimBlanks(s + i);
  2406.  
  2407.                if(*s != '\0')
  2408.                {
  2409.                  if (mLog) fprintf(stderr, "Incorrectly specified value:%s\n",
  2410.                                   *(c_ptr + index));
  2411.                  DeleteCDF(id);/* assumes that the id is a global var*/
  2412.                  ExitBAD;
  2413.                }
  2414.              }        
  2415.    
  2416.            *(uint1_ptr + index) = nuchar;/* copy this into the array */
  2417.  
  2418.  
  2419.          index++;/* the next element of that entry */
  2420.  
  2421.        }/* end while */
  2422.     }
  2423.     break;
  2424.     case CDF_UINT2:
  2425.     {
  2426.        index = 0;
  2427.  
  2428.        uint2_ptr = (unsigned short *) malloc(NumValues*sizeof(unsigned short));
  2429.                         /* an array of char*/
  2430.  
  2431.        while( index <= NumValues - 1)/* convert & copy the values */
  2432.        {
  2433.          s = *(c_ptr + index);
  2434.  
  2435.          if(*s == '-')/* a negative number */
  2436.          {
  2437.            if (mLog)
  2438.          fprintf(stderr,"Numeric value too large for this data type\n");
  2439.            DeleteCDF(id);/* assumes that the id is a global var*/
  2440.            ExitBAD;
  2441.          }
  2442.          else
  2443.            test_val = atoi(s);/* to check its range */
  2444.  
  2445.          if((test_val< 0)||(test_val > 65535))
  2446.           {
  2447.            if (mLog)
  2448.          fprintf(stderr,"Numeric value too large for the data type");
  2449.            DeleteCDF(id);/* assumes that the id is a global var*/
  2450.            ExitBAD;
  2451.           }         
  2452.  
  2453.          nushort = 0;
  2454.          
  2455.          for(i = 0;*(s + i) >= '0'&& *(s + i) <= '9'; ++i)
  2456.            nushort = 10*nushort + *(s + i) - '0';/* terminates if a non numeric
  2457.                                     char or if the value exceeds */
  2458.  
  2459.             if(*(s + i) != '\0')/* a non numeric char or a space*/
  2460.              {
  2461.                s = TrimBlanks(s + i);
  2462.  
  2463.                if(*s != '\0')
  2464.                {
  2465.                  if (mLog) fprintf(stderr, "Incorrectly specified value:%s\n",
  2466.                                   *(c_ptr + index));
  2467.                  DeleteCDF(id);/* assumes that the id is a global var*/
  2468.                  ExitBAD;
  2469.                }
  2470.              }        
  2471.    
  2472.            *(uint2_ptr + index) = nushort;/* copy this into the array */
  2473.  
  2474.  
  2475.          index++;/* the next element of that entry */
  2476.  
  2477.        }/* end while */
  2478.     }
  2479.     break;
  2480.     case CDF_UINT4:
  2481.     {
  2482.       uint4_ptr = (unsigned long *) malloc(NumValues*sizeof(unsigned long));
  2483.                              /* an array of in*/
  2484.        index = 0;
  2485.  
  2486.        while( index <= NumValues - 1)/* convert & copy the values */
  2487.        {
  2488.          s = *(c_ptr + index);
  2489.         
  2490.          if(*s == '-')
  2491.          {
  2492.             if (mLog)
  2493.           fprintf(stderr,"Numeric Value too large for the data type");
  2494.             DeleteCDF(id);/* assumes that the id is a global var*/
  2495.             ExitBAD;
  2496.          }
  2497.          else
  2498.           *(uint4_ptr + index) = atoi(s);
  2499.          index++;
  2500.        }
  2501.     }
  2502.     break;
  2503.     case CDF_REAL4:
  2504.     {
  2505.       real4_ptr = (float *) malloc(NumValues*sizeof(float));
  2506.                    /* an array of in*/
  2507.        index = 0;
  2508.  
  2509.        while( index <= NumValues - 1)/* convert & copy the values */
  2510.        {
  2511.          stringToReal4(*(c_ptr + index), &float_val);
  2512.          *(real4_ptr + index) = float_val;
  2513.          index++;
  2514.        }
  2515.     }
  2516.     break;
  2517.     case CDF_REAL8:
  2518.     {
  2519.  
  2520.       real8_ptr = (double *) malloc(NumValues*(sizeof(double)));
  2521.        /* an array of real*/
  2522.  
  2523.        index = 0;
  2524.  
  2525.        while(index <= NumValues - 1)/* convert & copy the values */
  2526.        {
  2527.                                 /* V1.1... */
  2528.          stringToReal8(*(c_ptr + index), &double_val);
  2529.          *(real8_ptr + index) = double_val;
  2530.                                 /* ...V1.1 */
  2531.          index++;
  2532.        }/* end while */
  2533.     }
  2534.     break;
  2535.     case CDF_EPOCH:
  2536.     {
  2537.  
  2538.       real8_ptr = (double *) malloc(NumValues*(sizeof(double)));
  2539.        /* an array of real*/
  2540.  
  2541.        index = 0;
  2542.  
  2543.        while(index <= NumValues - 1)/* convert & copy the values */
  2544.        {
  2545.                                 /* V1.1... */
  2546.          epochParse(*(c_ptr + index), &epoch);
  2547.          *(real8_ptr + index) = epoch.tSince0;
  2548.                                 /* ...V1.1 */
  2549.          index++;
  2550.        }/* end while */
  2551.     }
  2552.     break;
  2553.     case CDF_BYTE:
  2554.     {
  2555.       
  2556.        index = 0;
  2557.  
  2558.        int1_ptr = (Schar *) malloc(NumValues*sizeof(Schar));
  2559.  
  2560.        while( index <= NumValues - 1)/* convert & copy the values */
  2561.        {
  2562.          s = *(c_ptr + index);
  2563.  
  2564.          if(*s == '-')/* a negative number */
  2565.          {
  2566.            s++;/* get past */
  2567.            s = TrimBlanks(s);/* to get rid of blank spaces */
  2568.            test_val = -(atoi(s));
  2569.            s = *(c_ptr + index);/* reassign */
  2570.          }
  2571.          else
  2572.            test_val = atoi(s);/* to check its range */
  2573.  
  2574.          if((test_val< -128)||(test_val > 127))
  2575.           {
  2576.            if (mLog)
  2577.          fprintf(stderr,"Numeric value too large for the data type");
  2578.            DeleteCDF(id);/* assumes that the id is a global var*/
  2579.            ExitBAD;
  2580.           }         
  2581.  
  2582.   
  2583.          nchar = 0;
  2584.          
  2585.          if(*s == '-')
  2586.          {
  2587.            s++;/* get past*/
  2588.            s = TrimBlanks(s);/* to eliminate any blanks */
  2589.          }
  2590.  
  2591.          for(i = 0;*(s + i) >= '0'&& *(s + i) <= '9'; ++i)
  2592.            nchar = 10*nchar + *(s + i) - '0';/* terminates if a non numeric
  2593.                                     char or if the value exceeds */
  2594.  
  2595.             if(*(s + i) != '\0')/* a non numeric char or a space*/
  2596.              {
  2597.                s = TrimBlanks(s + i);
  2598.  
  2599.                if(*s != '\0')
  2600.                {
  2601.                  if (mLog) fprintf(stderr, "Incorrectly specified value:%s\n",
  2602.                                   *(c_ptr + index));
  2603.                  DeleteCDF(id);/* assumes that the id is a global var*/
  2604.                  ExitBAD;
  2605.                }
  2606.              }        
  2607.    
  2608.            *(int1_ptr + index) = nchar;/* copy this into the array */
  2609.  
  2610.            
  2611.           s = *(c_ptr + index);/* reassign */
  2612.           if(*s == '-')
  2613.           *(int1_ptr + index) = - *(int1_ptr + index);/* make it negative */
  2614.  
  2615.          index++;/* the next element of that entry */
  2616.  
  2617.        }/* end while */
  2618.     }
  2619.     break;
  2620.     case CDF_FLOAT:
  2621.    {
  2622.       real4_ptr = (float *) malloc(NumValues*sizeof(float));/* an array of in*/
  2623.  
  2624.        index = 0;
  2625.  
  2626.        while(index <= NumValues - 1)/* convert & copy the values */
  2627.        {
  2628.          stringToReal4(*(c_ptr + index), &float_val);
  2629.          *(real4_ptr + index) = float_val;
  2630.          index++;
  2631.        }
  2632.     }
  2633.     break;
  2634.     case CDF_DOUBLE:
  2635.    {
  2636.       real8_ptr = (double *) malloc(NumValues*sizeof(double));/* an array of in*/
  2637.        index = 0;
  2638.  
  2639.        while(index <= NumValues - 1)    /* convert & copy the values */
  2640.        {
  2641.          stringToReal8(*(c_ptr + index), &double_val);
  2642.          *(real8_ptr + index) = double_val;
  2643.          index++;
  2644.        }
  2645.     }
  2646.     break;
  2647.   }/* end switch */
  2648. }
  2649.  
  2650. /*---------------------------------------------------------------------*/
  2651.  
  2652. long ComputeNRVNum(vararray, numdims, dimsizes)
  2653. /* computes the product of all true dimensions */
  2654. /* returns zero if all dimensions are NOVARY */
  2655.  
  2656. long vararray[];/* an array that has info on the current var */
  2657. long numdims;/* number of dimensions of the CDF */
  2658. long dimsizes[];
  2659. {
  2660.   long value = 0, index;
  2661.  
  2662.   for(index=0;index<numdims;index++)
  2663.    {
  2664.     if(vararray[index + 1]== VARY)
  2665.      {
  2666.       if(value == 0)
  2667.         value++;
  2668.       value = value*(vararray[index + 1]*dimsizes[index]);
  2669.      } 
  2670.   }
  2671.    if(value < 0)
  2672.      value = -value;/* since VARY = -1 */
  2673.   return(value);
  2674. }
  2675.  
  2676. /*---------------------------------------------------------------------*/
  2677.  
  2678. void DeleteCDF(cdfid)
  2679. CDFid cdfid;
  2680. {
  2681.   CDFstatus status;
  2682.  
  2683.   status = CDFdelete(cdfid);
  2684.   StatusHandler (status);
  2685.  
  2686. return;
  2687. }
  2688.  
  2689. /*----------------------------------------------------------------------*/
  2690.  
  2691. void CloseCDF(cdfid)
  2692. CDFid cdfid;
  2693. {
  2694.   CDFstatus status;
  2695.  
  2696.   status = CDFclose(cdfid);
  2697.   StatusHandler (status);
  2698. }
  2699.  
  2700. /*---------------------------------------------------------------------*/
  2701.  
  2702. char SelDelimChr(attr_name)
  2703. char attr_name[];
  2704. {/*returns a char to be used as a delimiter in the skeleton table*/
  2705.   static char del_array[] = { '"','*','&','^','#' };
  2706.   long i;
  2707.   for(i= 0; i< 5; i++)
  2708.    {
  2709.      if(strchr(attr_name,*(del_array + i)) == 0)
  2710.      {
  2711.        return(*(del_array + i));
  2712.      }
  2713.    }/* end for */
  2714.   if (mLog) fprintf(stderr,"No right delimiter\n");
  2715.   DeleteCDF(id);/* assumes that the id is a global var*/
  2716.   ExitBAD;
  2717. #if defined(__MSDOS__)
  2718. return ' ';
  2719. #endif
  2720. }
  2721.  
  2722.  
  2723. #if 0
  2724. /*--------------------------------------------------------------*/
  2725.  
  2726. long ProductHigherDims(CurrentDim, DimSizes, numb_dims)
  2727. long CurrentDim;
  2728. long DimSizes[];
  2729. long numb_dims;
  2730. {
  2731.    long product, i;
  2732.  
  2733.    product = 1;
  2734.  
  2735.    for(i=(CurrentDim + 1); i<numb_dims; i++)
  2736.     {
  2737.        if(*(DimSizes + i) >0)
  2738.           product = product*(*(DimSizes + i));
  2739.  
  2740.     }/*end for */
  2741.  
  2742.    return(product);
  2743. }/* */
  2744.  
  2745. /*-------------------------------------------------------------*/
  2746.  
  2747. long ProductLowerDims(CurrentDim, DimSizes)
  2748. long CurrentDim;
  2749. long DimSizes[];
  2750. {
  2751.    long product, i;
  2752.  
  2753.    product = 1;
  2754.  
  2755.    for(i= 0; i<CurrentDim; i++)
  2756.     {
  2757.        if(*(DimSizes + i) >0)
  2758.           product = product*(*(DimSizes + i));
  2759.  
  2760.     }/*end for */
  2761.  
  2762.    return(product);
  2763. }/* */
  2764.  
  2765. /*---------------------------------------------------------------*/
  2766.  
  2767. long ComputeHIndexVector(current_item, numb_dims, 
  2768.                    dim_array, var_array, IndVect)
  2769. /* puts the index vector in the IndVect array, for row - major */
  2770. long current_item;
  2771. long numb_dims;/*number of dimensions */
  2772. long dim_array[];/*dimension array  of various sizes*/
  2773. long var_array[];/*variances array*/
  2774. long IndVect[];/* Indices */
  2775.  
  2776. {
  2777.   long i, fake_dims[CDF_MAX_DIMS], next, product, index;
  2778.  
  2779.    for(i=0;i<11;i++)
  2780.        *(IndVect + i) = 0;/* zero initialize it */
  2781.  
  2782.    for(i = 0; i<numb_dims;i++)
  2783.    {
  2784.       if(*(var_array + i) == VARY)
  2785.         *(fake_dims + i) = *(dim_array + i);
  2786.       else
  2787.         *(fake_dims + i) = 1;
  2788.  
  2789.       
  2790.    }/* for i*/
  2791.  
  2792.   next = current_item;
  2793.  
  2794.   for(i=0;i < numb_dims; i++)
  2795.    {
  2796.        product = ProductHigherDims( i, fake_dims, numb_dims);
  2797.        index = (long) (next/product);
  2798.        next = (next%product);
  2799.        *(IndVect + i) = index;
  2800.    }
  2801.  
  2802. return 0;    /* Not sure what to return, J Love */  
  2803. }
  2804.  
  2805. /*--------------------------------------------------------------*/
  2806.  
  2807. long ComputeLIndexVector(current_item, numb_dims, 
  2808.                    dim_array, var_array, IndVect)
  2809. /* puts the index vector in the IndVect array, for col - major */
  2810. long current_item;
  2811. long numb_dims;/*number of dimensions */
  2812. long dim_array[];/*dimension array  of various sizes*/
  2813. long var_array[];/*variances array*/
  2814. long IndVect[];/* Indices */
  2815.  
  2816. {
  2817.   long i, fake_dims[CDF_MAX_DIMS], next, product, index;
  2818.  
  2819.    for(i = 0; i<numb_dims;i++)
  2820.    {
  2821.       if(*(var_array + i) == VARY)
  2822.         *(fake_dims + i) = *(dim_array + i);
  2823.       else
  2824.         *(fake_dims + i) = 1;
  2825.  
  2826.       *(IndVect + i) = 0;/* initialize it */
  2827.    }/* for i*/
  2828.  
  2829.   next = current_item;
  2830.  
  2831.   for(i=numb_dims;i >= 0 ; i--)/*  */
  2832.    {
  2833.        product = ProductLowerDims( i, fake_dims);
  2834.        index = (long) (next/product);
  2835.        next = (next%product);
  2836.        *(IndVect + i) = index;
  2837.    }
  2838.   
  2839. return 0;    /* Not sure what to return, J Love */  
  2840. }
  2841. /*-----------------------------------------------------------------------*/
  2842. #endif
  2843.  
  2844.  
  2845. #if 0
  2846. extern void prtext ( output, format, text )
  2847.  
  2848.  FILE *output; 
  2849.  char *format; 
  2850.  char *text[];
  2851.  
  2852.    /*
  2853.     * Print an array of strings (*text[]) to file output using format.
  2854.     * Function iterates on:   fprintf (output, format, text[j]);
  2855.     * A null string signals end of the array.
  2856.     */
  2857.                         /*CodeRef-mark*/
  2858. {  
  2859.    long j, nullstring = 0;
  2860.    for (j=0;  text[j][0] != nullstring; j++)
  2861.       fprintf (output, format, text[j]);
  2862. }  /* end prtext */
  2863. #endif
  2864.  
  2865. /*-------------------------------------------------------------------*/
  2866.  
  2867. char *strupper ( string )
  2868.  
  2869. char *string;
  2870.  
  2871.      /*
  2872.       *  Converts a string to all upper-case, permanent change.
  2873.       *  The string must be NULL-terminated.
  2874.       *  Return value is the pointer to the string.
  2875.       */
  2876.                         
  2877. {
  2878.      char *saveptr;
  2879.      saveptr = string;
  2880.  
  2881.      while (*string != '\0')
  2882.            {
  2883.             if((isalpha(*string))&&(islower(*string)))
  2884.                *string = toupper(*string);
  2885.             string++;
  2886.            }
  2887.      string = saveptr;
  2888.      return (string);
  2889. }  /* end strupper */
  2890.  
  2891. /*-------------------------------------------------------------------*/
  2892.  
  2893. long stringToInt2( string, integer)
  2894.  
  2895. char *string;
  2896. short *integer;
  2897.  
  2898.       {
  2899.         short temp;
  2900.         long res = 0;
  2901.         sscanf(string, "%d", &temp);
  2902.  
  2903.        *integer = temp;
  2904.         return(res);
  2905.  
  2906.       }  
  2907. /*----------------------------------------------------------------------*/
  2908.  
  2909. long stringToInt4( string, integer)
  2910.  
  2911. char *string;
  2912. long *integer;
  2913.  
  2914.       {
  2915.         long temp;
  2916.         long res = 0;
  2917.  
  2918.         sscanf(string, "%ld", &temp);
  2919.  
  2920.        *integer = temp;
  2921.  
  2922.         return(res);
  2923.       }  
  2924. /*----------------------------------------------------------------------*/
  2925.  
  2926. long stringToReal4( string, real_num)
  2927.  
  2928. char *string;
  2929. float *real_num;
  2930.  
  2931.       {
  2932.         float temp;
  2933.         long res = 0;
  2934.     
  2935.         sscanf(string, "%f", &temp);
  2936.  
  2937.         *real_num = temp;
  2938.  
  2939.         return(res);
  2940.       }
  2941. /*---------------------------------------------------------------------*/
  2942.  
  2943. long stringToReal8( string, real_num)
  2944.  
  2945. char *string;
  2946. double *real_num;
  2947.  
  2948.       {
  2949.         double temp;/* dummy variable */
  2950.         long res = 0;/* dummy return code to emulate the fortran version */
  2951.  
  2952.         sscanf(string, "%lf", &temp);
  2953.  
  2954.         *real_num = temp;
  2955.  
  2956.         return(res);
  2957.       }
  2958. /*----------------------------------------------------------------------*/
  2959.  
  2960. #if 0
  2961. long stringspn(string, chr)
  2962. char *string;
  2963. char *chr;
  2964. {
  2965.    long pos, flag;
  2966.    char *temp_addr;
  2967.  
  2968.    flag = 0;
  2969.    temp_addr = string;
  2970.  
  2971.       while(!flag)
  2972.         {
  2973.           if(*string == *chr)
  2974.             {
  2975.             pos = string-temp_addr;
  2976.             ++flag;
  2977.             }
  2978.           else if(*string=='\0')
  2979.             {
  2980.               pos = strlen(temp_addr);
  2981.               ++flag;
  2982.              }
  2983.          else
  2984.             string++; 
  2985.         }
  2986.  
  2987.         return(pos);
  2988.      }
  2989. /*----------------------------------------------------------------------*/
  2990. #endif
  2991.  
  2992.  
  2993. #if 0    /* THIS IS A BIZARRE WAY TO DO IT */
  2994. extern char *trimToLast ( string, chr )
  2995.  char *string;
  2996.  char chr;
  2997.  
  2998. {
  2999.  /* This function Trims from beginning of string to last 'chr' by whittling. */
  3000.  
  3001.  char              *saveString;
  3002.  
  3003.  long               pos = 0;
  3004.  
  3005.  saveString = (char *) malloc (strlen(string) +1);
  3006.  strcpy (saveString, string);
  3007.   
  3008. /* Trim from beginning of string to last 'chr' by whittling. */
  3009.  
  3010. while (pos = (stringspn(saveString, &chr) < strlen(saveString)))
  3011.     {
  3012.      strcpy (string, &saveString[pos]);
  3013.      strcpy (saveString, string);
  3014.     }
  3015.  free (saveString);
  3016.  return (string);
  3017. }  /* end trimToLast */
  3018. #endif
  3019.  
  3020. #if 0
  3021. /* HOPEFULLY THIS MAKES MORE SENSE TO TURBO-C ON THE IBM-PC */
  3022.  
  3023. char *trimToLast (string, chr)
  3024. char *string;
  3025. char chr;
  3026. {
  3027. char *cp;
  3028. if ((cp = strrchr(string,chr)) != NULL)
  3029.   memmove (string, cp + 1, strlen(cp+1) + 1);
  3030. return string;
  3031. }
  3032. /*--------------------------------------------------------------------*/
  3033. #endif
  3034.  
  3035.  
  3036. #if 0
  3037. char *trimToFirst ( string , chr)
  3038.  
  3039.  char *string;
  3040.  char chr;
  3041. {
  3042. /*      
  3043.         this function trims UPTO the first occurance of the given 
  3044.         character chr
  3045. */
  3046.  
  3047.  char                *saveString;
  3048.  
  3049.  long                 pos = 0;
  3050.  
  3051.  saveString = ( char *)malloc (strlen(string) +1);
  3052.  strcpy (saveString, string);
  3053.   
  3054.  if(chr == '/')
  3055.    {
  3056.     while(( pos = stringspn (saveString, &chr)) <strlen(saveString))
  3057.      {
  3058.       strcpy (string, &saveString[pos+1]);
  3059.       strcpy (saveString, string);
  3060.      }
  3061.    }
  3062.   else
  3063.    {
  3064.     if (( pos = stringspn (saveString, &chr)) <strlen(saveString))
  3065.      {
  3066.       strcpy (string, &saveString[pos+1]);
  3067.       strcpy (saveString, string);
  3068.      }
  3069.    }
  3070.  free (saveString);
  3071.  return (string);
  3072. }  /* end trimToFirst */
  3073. /*-------------------------------------------------------------------*/
  3074. #endif
  3075.  
  3076.  
  3077. char *ProcessWrapLines(fp, buffer, message)
  3078. FILE *fp;
  3079. char buffer[];
  3080. char message[];
  3081. {
  3082.  
  3083.    long flag = 0, len;
  3084.    char *buff;
  3085.  
  3086.    while(flag == 0)
  3087.    {
  3088.       if(fgets(buffer, 134, fp) == NULL)
  3089.       {
  3090.          if (mLog) fprintf(stderr,"%s\n", message);
  3091.          DeleteCDF(id);
  3092.          ExitBAD;
  3093.       }
  3094.  
  3095.       len = strlen(buffer);
  3096.  
  3097.       *(buffer + (len - 1)) = '\0';
  3098.  
  3099.       buff = TrimBlanks(buffer);
  3100.  
  3101.       switch(*buff)
  3102.       {
  3103.         case '\0':
  3104.          {
  3105.            buff = ProcessWrapLines(fp,buffer, message);
  3106.            flag++;
  3107.          }
  3108.         break;
  3109.         case '!':
  3110.          {
  3111.            buff = ProcessWrapLines(fp, buffer, message);
  3112.            flag++;
  3113.          }
  3114.         break;
  3115.         default:
  3116.           flag++;
  3117.         break;
  3118.       }/* end switch */
  3119.    }/* end  while */ 
  3120.  
  3121.     return(buff);
  3122.  
  3123. }/* ProcessWrapLines */
  3124.  
  3125. /*--------------------------------------------------------------------------*/
  3126.  
  3127. long IsDelimString(addr )/* checks if the string is delimited string or
  3128.                               not */
  3129. char addr[];
  3130. {
  3131.    long ret;
  3132.    char delim;
  3133.  
  3134.     delim = *addr;
  3135.  
  3136.     if((isdigit(*addr) != 0)||(isalpha(*addr) != 0))
  3137.       {
  3138.         ret = 0; 
  3139.         return(ret);
  3140.       }
  3141.  
  3142.     addr++;/* move by 1 */
  3143.  
  3144.     while((*addr != delim)&&(*addr != '\0'))
  3145.       addr++;
  3146.  
  3147.     switch(*addr)
  3148.      {
  3149.       case '\0':
  3150.       {
  3151.         ret = 0;
  3152.         break;
  3153.       }
  3154.       default:
  3155.       {
  3156.         ret = 1;
  3157.         break;
  3158.       }
  3159.  
  3160.      }
  3161. return(ret);
  3162. }/* isDelimString */
  3163.  
  3164. /*--------------------------------------------------------------------------*/
  3165.  
  3166. /******************************************************************************
  3167. * StatusHandler.
  3168. ******************************************************************************/
  3169.  
  3170. void StatusHandler (status)
  3171. CDFstatus status;
  3172. {
  3173. char text[CDF_STATUSTEXT_LEN + 1];
  3174.  
  3175. if (status == CDF_OK) return;        /* Do nothing. */
  3176.  
  3177. CDFlib (SELECT_, CDF_STATUS_, status,
  3178.     GET_, STATUS_TEXT_, text,
  3179.     NULL_);
  3180.  
  3181. if (status < CDF_WARN) {
  3182.   printf ("\nERROR> %s\n", text);
  3183.   CDFdelete (id);            /* Return status ignored. */
  3184.   ExitBAD;
  3185. }
  3186. else
  3187.   if (mLog)
  3188.     if (status < CDF_OK)
  3189.       printf ("WARNING> %s\n", text);
  3190.     else
  3191.       printf ("INFO> %s\n", text);
  3192.  
  3193. return;
  3194. }
  3195.